#include <bits/stdc++.h>
using namespace std;
const double EPS = (1e-7);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }
const int OO = (int)1e6;
pair<long long, pair<long long, long long> > extendedEuclid(long long a,
                                                            long long b) {
  if (a == 0) return make_pair(b, make_pair(0, 1));
  pair<long long, pair<long long, long long> > p;
  p = extendedEuclid(b % a, a);
  return make_pair(
      p.first,
      make_pair(p.second.second - p.second.first * (b / a), p.second.first));
}
long long modInverse(long long a, long long m) {
  return (extendedEuclid(a, m).second.first + m) % m;
}
long long powmod(long long base, long long pw, long long mod) {
  long long ret = 1;
  while (pw) {
    if (pw & 1) ret = (ret * base) % mod;
    base = (base * base) % mod;
    pw >>= 1;
  }
  return ret;
}
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  return GCD(b, a % b);
}
long long LCM(long long a, long long b) { return (a / GCD(a, b)) * b; }
long long Bigmod(long long x, long long y, long long m) {
  if (y == 0) return 1 % m;
  if (y % 2 == 0) {
    long long temp = Bigmod(x, y / 2, m);
    return (temp * temp) % m;
  }
  return (x % m * Bigmod(x, y - 1, m)) % m;
}
const int MAX_N = 1000000;
vector<int> primes;
bool is_prime[MAX_N];
void sieve() {
  for (int i = 0; i < MAX_N; i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < MAX_N; i++) {
    if (is_prime[i]) {
      primes.push_back(i);
      for (int j = i + i; j < MAX_N; j += i) is_prime[j] = false;
    }
  }
}
vector<int> prime_Factors(long long N) {
  vector<int> factors;
  long long PF_idx = 0, PF = primes[PF_idx];
  while (N != 1 && (PF * PF <= N)) {
    while (N % PF == 0) {
      N /= PF;
      factors.push_back(PF);
    }
    PF = primes[++PF_idx];
  }
  if (N != 1) factors.push_back(N);
  return factors;
}
long long numPF(long long N) {
  long long PF_idx = 0, PF = primes[PF_idx], ans = 0;
  while (N != 1 && (PF * PF <= N)) {
    while (N % PF == 0) {
      N /= PF;
      ans++;
    }
    PF = primes[++PF_idx];
  }
  if (N != 1) ans++;
  return ans;
}
long long numDiv(long long N) {
  long long PF_idx = 0, PF = primes[PF_idx], ans = 1;
  while (N != 1 && (PF * PF <= N)) {
    long long power = 0;
    while (N % PF == 0) {
      N /= PF;
      power++;
    }
    ans *= (power + 1);
    PF = primes[++PF_idx];
  }
  if (N != 1) ans *= 2;
  return ans;
}
long long sumDiv(long long N) {
  long long PF_idx = 0, PF = primes[PF_idx], ans = 1;
  while (N != 1 && (PF * PF <= N)) {
    long long power = 0;
    while (N % PF == 0) {
      N /= PF;
      power++;
    }
    ans *= ((long long)pow((double)PF, power + 1.0) - 1) / (PF - 1);
    PF = primes[++PF_idx];
  }
  if (N != 1) ans *= ((long long)pow((double)N, 2.0) - 1) / (N - 1);
  return ans;
}
long long modulo(long long m, long long n) {
  return m >= 0 ? m % n : (n - abs(m % n)) % n;
}
long long n;
int sum(long long x) {
  int sum = 0;
  while (x) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}
int ok(long long mid) {
  long long x = sum(mid);
  long long y = x * mid - n;
  if (y >= 0) return 2;
  if (y < 0) y *= -1;
  if (dcmp(sqrt(y), mid) == 0)
    return 0;
  else if (dcmp(sqrt(y), mid) == 1)
    return 1;
  return 1;
}
long long delta(long long x) { return sqrt(pow(x, 2) + 4 * n); }
long long power(long long x) { return pow(x, 2) + 4 * n; }
int main() {
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < 91; i++) {
    long long d = delta(i);
    if (d * d != power(i)) continue;
    long long x = (-i + d) / 2;
    if (sum(x) == i) {
      return cout << x << endl, 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

### Prompt

Your task is to create a Cpp solution to the following problem:

Let's consider equation:

x2 + s(x)·x - n = 0, 

where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system.

You are given an integer n, find the smallest positive integer root of equation x, or else determine that there are no such roots.

Input

A single line contains integer n (1 ≤ n ≤ 1018) — the equation parameter.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. 

Output

Print -1, if the equation doesn't have integer positive roots. Otherwise print such smallest integer x (x > 0), that the equation given in the statement holds.

Examples

Input

2


Output

1


Input

110


Output

10


Input

4


Output

-1

Note

In the first test case x = 1 is the minimum root. As s(1) = 1 and 12 + 1·1 - 2 = 0.

In the second test case x = 10 is the minimum root. As s(10) = 1 + 0 = 1 and 102 + 1·10 - 110 = 0.

In the third test case the equation has no roots.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const double EPS = (1e-7);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }
const int OO = (int)1e6;
pair<long long, pair<long long, long long> > extendedEuclid(long long a,
                                                            long long b) {
  if (a == 0) return make_pair(b, make_pair(0, 1));
  pair<long long, pair<long long, long long> > p;
  p = extendedEuclid(b % a, a);
  return make_pair(
      p.first,
      make_pair(p.second.second - p.second.first * (b / a), p.second.first));
}
long long modInverse(long long a, long long m) {
  return (extendedEuclid(a, m).second.first + m) % m;
}
long long powmod(long long base, long long pw, long long mod) {
  long long ret = 1;
  while (pw) {
    if (pw & 1) ret = (ret * base) % mod;
    base = (base * base) % mod;
    pw >>= 1;
  }
  return ret;
}
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  return GCD(b, a % b);
}
long long LCM(long long a, long long b) { return (a / GCD(a, b)) * b; }
long long Bigmod(long long x, long long y, long long m) {
  if (y == 0) return 1 % m;
  if (y % 2 == 0) {
    long long temp = Bigmod(x, y / 2, m);
    return (temp * temp) % m;
  }
  return (x % m * Bigmod(x, y - 1, m)) % m;
}
const int MAX_N = 1000000;
vector<int> primes;
bool is_prime[MAX_N];
void sieve() {
  for (int i = 0; i < MAX_N; i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < MAX_N; i++) {
    if (is_prime[i]) {
      primes.push_back(i);
      for (int j = i + i; j < MAX_N; j += i) is_prime[j] = false;
    }
  }
}
vector<int> prime_Factors(long long N) {
  vector<int> factors;
  long long PF_idx = 0, PF = primes[PF_idx];
  while (N != 1 && (PF * PF <= N)) {
    while (N % PF == 0) {
      N /= PF;
      factors.push_back(PF);
    }
    PF = primes[++PF_idx];
  }
  if (N != 1) factors.push_back(N);
  return factors;
}
long long numPF(long long N) {
  long long PF_idx = 0, PF = primes[PF_idx], ans = 0;
  while (N != 1 && (PF * PF <= N)) {
    while (N % PF == 0) {
      N /= PF;
      ans++;
    }
    PF = primes[++PF_idx];
  }
  if (N != 1) ans++;
  return ans;
}
long long numDiv(long long N) {
  long long PF_idx = 0, PF = primes[PF_idx], ans = 1;
  while (N != 1 && (PF * PF <= N)) {
    long long power = 0;
    while (N % PF == 0) {
      N /= PF;
      power++;
    }
    ans *= (power + 1);
    PF = primes[++PF_idx];
  }
  if (N != 1) ans *= 2;
  return ans;
}
long long sumDiv(long long N) {
  long long PF_idx = 0, PF = primes[PF_idx], ans = 1;
  while (N != 1 && (PF * PF <= N)) {
    long long power = 0;
    while (N % PF == 0) {
      N /= PF;
      power++;
    }
    ans *= ((long long)pow((double)PF, power + 1.0) - 1) / (PF - 1);
    PF = primes[++PF_idx];
  }
  if (N != 1) ans *= ((long long)pow((double)N, 2.0) - 1) / (N - 1);
  return ans;
}
long long modulo(long long m, long long n) {
  return m >= 0 ? m % n : (n - abs(m % n)) % n;
}
long long n;
int sum(long long x) {
  int sum = 0;
  while (x) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}
int ok(long long mid) {
  long long x = sum(mid);
  long long y = x * mid - n;
  if (y >= 0) return 2;
  if (y < 0) y *= -1;
  if (dcmp(sqrt(y), mid) == 0)
    return 0;
  else if (dcmp(sqrt(y), mid) == 1)
    return 1;
  return 1;
}
long long delta(long long x) { return sqrt(pow(x, 2) + 4 * n); }
long long power(long long x) { return pow(x, 2) + 4 * n; }
int main() {
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < 91; i++) {
    long long d = delta(i);
    if (d * d != power(i)) continue;
    long long x = (-i + d) / 2;
    if (sum(x) == i) {
      return cout << x << endl, 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

```