#include <iostream>
#include <fstream>
#include <vector>
#include <cassert>

using namespace std;

const int MAXK = 60;

int main()
{
	ifstream in("stones.in");
	ofstream out("stones.out");
	long long k, n;
	in >> n >> k;
	vector<long long> values;
	for (int i = 1; i < MAXK; i++)
		for (int j = 0; i + j < MAXK; j++)
		{
			long long now = ((1LL << i) - 1) << j;
			if (now <= k)
				values.push_back(now);
		}
	size_t m = values.size();
	cerr << m << "\n";
	assert (m < 30);
	int ans = 0;
	for (int mask = 0; mask < (1 << m); mask++)
	{
		long long now = 0;
		for (size_t j = 0; j < m; j++)
			if (((mask >> j) & 1) == 1)
				now ^= values[j];
		if (now == n)
			ans++;
	}
	out << ans << "\n";
}
