#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np N, M = map(int, read().split()) MOD = 10 ** 9 + 7 def coef_of_generating_function(P, Q, N): """compute the coefficient [x^N] P/Q of rational power series. Parameters ---------- P : np.ndarray numerator. Q : np.ndarray denominator Q[0] == 1 and len(Q) == len(P) + 1 is assumed. N : int The coefficient to compute. """ def convolve(f, g): return np.convolve(f, g) % MOD while N: Q1 = Q.copy() Q1[1::2] = np.negative(Q1[1::2]) if N & 1: P = convolve(P, Q1)[1::2] else: P = convolve(P, Q1)[::2] Q = convolve(Q, Q1)[::2] N >>= 1 return P[0] def fibonacci(N): P = np.array([0, 1], np.int64) Q = np.array([1, -1, -1], np.int64) return coef_of_generating_function(P, Q, N) A = fibonacci(M) B = fibonacci(M + M) L = B * pow(int(A), MOD - 2, MOD) % MOD P = np.array([0, A], np.int64) Q = np.array([1, -L, (-1) ** M], np.int64) Q = np.convolve(Q, [1, -1]) answer = coef_of_generating_function(P, Q, N) print(answer)