#include <bits/stdc++.h>
using namespace std;
long long n;
int sum(long long n) {
  long long s = 0;
  while (n > 0) {
    s += n % 10;
    n /= 10;
  }
  return s;
}
long long ff(long long x) {
  long long tmp = x * x + sum(x) * x - n;
  return tmp;
}
int main() {
  cin >> n;
  for (long long i = 1; i <= 90; i++) {
    long long tmp = (i * i + 4 * n);
    long long x1 = (-i + sqrt(tmp)) / 2;
    long long x2 = (-i - sqrt(tmp)) / 2;
    if (x1 >= 0 && sum(x1) == i && ff(x1) == 0) {
      cout << x1 << endl;
      return 0;
    }
    if (x2 >= 0 && sum(x2) == i && ff(x2) == 0) {
      cout << x2 << endl;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
