#include <bits/stdc++.h>
using namespace std;
const int OO = (1 << 30) - 1;
const int MAXN = (64) + 1;
map<pair<long long, long long>, long long> mm;
long long count(long long n, long long t) {
  if (mm.find(pair<long long, long long>(n, t)) == mm.end()) {
    long long res = (t == 1);
    if (n > 1) {
      long long x;
      for (x = 1; 2 * x + 1 < n; x = 2 * x + 1) continue;
      res += count(x, t);
      if (t % 2 == 0 and n > x + 1) res += count(n - x - 1, t / 2);
    }
    mm[pair<long long, long long>(n, t)] = res;
  }
  if (0)
    cout << "count(" << n << ", " << t
         << "):" << mm[pair<long long, long long>(n, t)] << endl;
  return mm[pair<long long, long long>(n, t)];
}
int main() {
  long long n, t;
  cin >> n >> t;
  cout << (count(n + 1, t) - (t == 1)) << endl;
  return 0;
}
