Fibonacci numbers and their greatest common divisor

Compute the GCD of the nth and mth Fibonacci numbers for n and m up to 1e18, output modulo 1,000,000,007.

Medium7Number theoryMatrixMathNo attempts yetTime limit1sMemory limit256 MB

Problem

The Fibonacci numbers start with 0 and 1. The 0th Fibonacci number is 0, and the 1st is 1. From index 2 on, each number is the sum of the two before it.

Written as a formula, Fn=Fn1+Fn2 (n2)F_n = F_{n-1} + F_{n-2}\ (n \ge 2).

The Fibonacci numbers up to n=17n = 17 are:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597

Given nn and mm, write a program that computes the greatest common divisor of the nnth Fibonacci number and the mmth Fibonacci number.

Input

The first line contains nn and mm, separated by a space. Both nn and mm are natural numbers no greater than 101810^{18}.

Output

Print the greatest common divisor of the nnth Fibonacci number and the mmth Fibonacci number, modulo 1,000,000,007. Take the greatest common divisor of the actual Fibonacci numbers first, then reduce it modulo 1,000,000,007.