#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, cnt = 0, st = 0;
  bool memo[10];
  for (int i = 0; i < (10); i++) memo[i] = false;
  cin >> n >> k;
  for (int i = 0; i < (n); i++) {
    st = (7 * i * 9 + 81) % 11;
    if (memo[st] == false)
      if (st == k || (st + 9) % 11 == k || (st + 7) % 11 == k ||
          (st + 5) % 11 == k || (st + 3) % 11 == k) {
        cnt++;
        memo[st] = true;
      } else
        ;
    else
      cnt++;
  }
  cout << cnt << endl;
}
