import static java.lang.Math.max;
import static java.lang.System.arraycopy;
import static java.util.Arrays.deepToString;

import java.io.*;
import java.util.*;

public class stones_nn_slow {

	static final int MOD = 1000000007;

	static void solve() throws Exception {
		long n = nextLong();
		long k = nextLong();
		out.println(solve(n, k));
	}

	static int solve(long n, long k) {
		int bits = Long.numberOfTrailingZeros(Long.highestOneBit(max(n, k))) + 1;
		int[] dp = new int[1 << bits];
		dp[0] = 1;
		int[] dp2 = new int[1 << bits];
		for (int i = 1; i <= k; i++) {
			int p = i >> Integer.numberOfTrailingZeros(i);
			if ((p & (p + 1)) == 0) {
				arraycopy(dp, 0, dp2, 0, dp.length);
				for (int j = 0; j < dp.length; j++) {
					dp2[j ^ i] += dp[j];
					if (dp2[j ^ i] >= MOD) {
						dp2[j ^ i] -= MOD;
					}
				}
				int[] t = dp;
				dp = dp2;
				dp2 = t;
			}
		}
		return dp[(int) n];
	}

	static BufferedReader br;
	static StringTokenizer st;
	static PrintWriter out;

	static void debug(Object... a) {
		System.err.println(deepToString(a));
	}

	static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	static String next() throws IOException {
		while (st == null || !st.hasMoreTokens()) {
			String line = br.readLine();
			if (line == null) {
				return null;
			}
			st = new StringTokenizer(line);
		}
		return st.nextToken();
	}

	static long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}

	public static void main(String[] args) {
		try {
			File file = new File("stones.in");
			InputStream input = System.in;
			OutputStream output = System.out;
			if (file.canRead()) {
				input = (new FileInputStream(file));
				output = (new PrintStream("stones.out"));
			}
			br = new BufferedReader(new InputStreamReader(input));
			out = new PrintWriter(output);
			solve();
			out.close();
			br.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}
