

import java.util.Scanner;

public class Solution {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int mod=1000000000+7;

        int n = scanner.nextInt();
        int m = scanner.nextInt();

        //int[] dp = new int[m];
        int one=2;
        int two=4;

        for(int i=2; i<m; i++) {
            if(i%2==0) one = (int)((long)one*3)%mod;
            else two = (int)((long)two*3)%mod;
        }
        //System.out.println(modulo(2, 10000, mod));
        int ans = (int)((long)power(2, n, mod) + (long)(m%2==0 ? two : one ) -2); 
        System.out.println(ans%mod);
    }

    static int modulo(int a,int b,int c) {
        long x=1;
        long y=a;
        while(b > 0){
            if(b%2 == 1){
                x=(x*y)%c;
            }
            y = (y*y)%c; // squaring the base
            b /= 2;
        }
        return (int) x%c;
    }

    static int power(int x, int y, int p) {
        int res = 1;      // Initialize result

        x = x % p;  // Update x if it is more than or
        // equal to p

        while (y > 0) {
            // If y is odd, multiply x with result
            if (y%2==1)
                res = (res*x) % p;

            // y must be even now
            y = y>>1; // y = y/2
            x = (x*x) % p;
        }
        return res;
    }

}
