#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, ch = getchar(), f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
long long n, s;
vector<int> tmp;
void check(long long x) {
  tmp.clear();
  long long t = n;
  while (t) {
    tmp.push_back(t % x);
    t /= x;
  }
  int sum = 0;
  for (int i = 0; i < tmp.size(); ++i) sum += tmp[i];
  if (sum == s) {
    cout << x << endl;
    exit(0);
  }
}
int main() {
  cin >> n >> s;
  long long t;
  if (n == s) {
    cout << n + 1 << endl;
    return 0;
  }
  long long ans = 1ll << 60;
  for (long long j, t = 1; t <= n; t = j + 1) {
    long long p = n / t;
    j = n / p;
    if (n + p - s >= 0 && (n + p - s) % p == 0) {
      long long b = (n + p - s) / p;
      if (0 <= p && p < b && 0 <= n - p * b && n - p * b < b) {
        ans = min(ans, b);
      }
      return 0;
    }
  }
  if (ans == 1ll << 60) {
    cout << ans << endl;
  } else
    cout << -1 << endl;
  return 0;
}
