#include <bits/stdc++.h>
using namespace std;
const int maxN = 110;
int a[maxN][maxN];
void fill(int m) {
  for (int j = 1; j <= m; ++j) {
    a[1][j] = 0;
  }
  a[1][m + 1] = 1;
  for (int i = 2; i <= m + 1; ++i) {
    for (int j = 1; j <= m + 1; ++j) {
      if (j == 1) {
        a[i][j] = a[i - 1][j + 1];
      } else if (j == m + 1) {
        a[i][j] = a[i - 1][j - 1];
      } else {
        a[i][j] = a[i - 1][j - 1] ^ a[i - 1][j + 1];
      }
    }
  }
}
long long s[maxN][maxN];
long long get(long long left, long long right, int num, int index) {
  if (num < 0) {
    return 0;
  }
  if (index == 0) {
    return num == 0;
  }
  long long middle = left + (1LL << (index - 1)) - 1;
  if (right <= middle) {
    return get(left - (1LL << (index - 1)), right - (1LL << (index - 1)), num,
               index - 1);
  }
  return s[index - 1][num] +
         get(left, right - (1LL << (index - 1)), num - 1, index);
}
int brute(long long n, long long t) {
  int result = 0;
  for (int m = 1; m <= n; ++m) {
    memset(a, 0, sizeof(a));
    fill(m);
    int sum = 0;
    for (int i = 0; i <= m + 1; ++i) {
      sum += a[m + 1][i];
    }
    if (sum == t) {
      cerr << m << endl;
      ++result;
    }
  }
  return result;
}
int main() {
  long long n, t;
  cin >> n >> t;
  long long nt = t;
  while (nt % 2 == 0) {
    nt /= 2;
  }
  if (nt != 1) {
    cout << 0 << endl;
    return 0;
  }
  long long l = 1, r = 1;
  s[0][0] = 1;
  for (long long i = 1; i < 50; ++i) {
    l = r + 1, r += (1LL << i);
    for (long long j = 0; j < 50; ++j) {
      s[i][j] += s[i - 1][j];
      if (j + 1 < 50) {
        s[i][j + 1] += s[i - 1][j];
      }
    }
  }
  long long result = 0;
  if (t == 1) --result;
  int num = 0;
  while (t % 2 == 0) {
    ++num;
    t /= 2;
  }
  l = 1, r = 1;
  long long step = 1;
  int index = 0;
  while (r < n + 1) {
    result += s[index][num];
    step *= 2LL;
    ++index;
    l = r + 1, r += step;
  }
  result += get(l, n + 1, num, index);
  cout << result << endl;
  return 0;
}
