import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { new Main().run(); } final long MOD = 1_000_000_000 + 7; void run() { Scanner sc = new Scanner(System.in); long N = sc.nextLong(); long M = sc.nextLong(); long[][] mat = new long[][] { { 1, 1 }, { 1, 0 } }; mat = pow(mat, M); long[][] v = { { 1 }, { 0 } }; long[][] E = { { 1, 0 }, { 0, 1 } }; System.out.println(mul(mul(mat, mul(sub(E, pow(mat, N)), inv(sub(E, mat)))), v)[1][0]); } long[][] sub(long[][] a, long[][] b) { long[][] ret = new long[a.length][a[0].length]; for (int i = 0; i < a.length; ++i) { for (int j = 0; j < b[i].length; ++j) { ret[i][j] = (a[i][j] - b[i][j] + MOD) % MOD; } } return ret; } long[][] pow(long[][] a, long n) { long[][] ret = new long[a.length][a.length]; for (int i = 0; i < ret.length; ++i) ret[i][i] = 1; for (; n > 0; n >>= 1, a = mul(a, a)) { if (n % 2 == 1) { ret = mul(a, ret); } } return ret; } long[][] mul(long[][] a, long[][] b) { long[][] ret = new long[a.length][b[0].length]; for (int i = 0; i < a.length; ++i) { for (int j = 0; j < b[i].length; ++j) { for (int k = 0; k < a[i].length; ++k) { ret[i][j] = (ret[i][j] + a[i][k] * b[k][j] % MOD) % MOD; } } } return ret; } long[][] inv(long[][] a) { if (a.length != 2 || a[0].length != 2) { throw new AssertionError(); } long det = (a[0][0] * a[1][1] % MOD - a[0][1] * a[1][0] % MOD + MOD) % MOD; long coe = inv(det); if (det * coe % MOD != 1) throw new AssertionError(); long[][] ret = new long[][] { { coe * a[1][1] % MOD, (MOD - coe * a[0][1] % MOD) % MOD }, { (MOD - coe * a[1][0] % MOD) % MOD, coe * a[0][0] % MOD } }; return ret; } long pow(long a, long n) { long ret = 1; for (; n > 0; n >>= 1, a = a * a % MOD) { if (n % 2 == 1) { ret = ret * a % MOD; } } return ret; } long inv(long a) { return pow(a, MOD - 2); } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }