#include<bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	string X; cin >> X;
	long long M; cin >> M;
	int length = X.length();
	if (length == 1) {
		cout << (X[0] - 48 <= M); 
		exit(0);
	}
	long long n = pow(M / (X[0] - 48), 1. / (length - 1)) - 1;
	long long d = 0;
	for (char x : X) {
		d = max((int)d, x - 48);
	}
	n = max(n, d);
	while (true) {
		long long res = 0;
		for (int i = 0; i < length; ++i) {
			if (res >= LLONG_MAX / n) {
				cout << max(0ll, n - d - 1);
				exit(0);
			}
			res = res * n + (X[i] - 48);
		}
		if (res > M) {
			cout << max(0ll, n - d - 1);
			exit(0);
		}
		++n;
	}
	assert(false);
}	
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define debugArray(x, n)                                      \
  cerr << __LINE__ << ": " << #x << " = {";                   \
  for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];                   \
  cerr << "}" << '\n'
#define debugMatrix(x, h, w)                                         \
  cerr << __LINE__ << ": " << #x << " =\n";                          \
  for (long long hoge = 0; (hoge) < (long long)(h); ++(hoge)) {      \
    cerr << ((hoge ? " {" : "{{"));                                  \
    for (long long fuga = 0; (fuga) < (long long)(w); ++(fuga))      \
      cerr << ((fuga ? ", " : "")) << x[hoge][fuga];                 \
    cerr << "}" << (hoge + 1 == (long long)(h) ? "}" : ",") << '\n'; \
  }
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#define debugMatrix(x, h, w) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N, M;
  cin >> N >> M;
  const int OFS = 100000000;
  if (N == 1) {
    if (M == 0) {
      cout << 1 << " " << 2 << '\n';
    } else {
      cout << -1 << '\n';
    }
  } else if (M < 0 || M > N - 2) {
    cout << -1 << '\n';
  } else {
    cout << 1 << " " << OFS + 1 << '\n';
    for (int i = 1; i <= M + 1; i++) {
      cout << 2 * i << " " << 2 * i + 1 << '\n';
    }
    for (int i = 1; i <= N - (M + 2); i++) {
      cout << OFS + 2 * i << " " << OFS + 2 * i + 1 << '\n';
    }
  }
  return 0;
}