#include <bits/stdc++.h>
using namespace std;
long long cp(long long x) {
  long long s = 0;
  while (x) {
    s += x % 10;
    x /= 10;
  }
  return s;
}
int main() {
  long long n, x, s, f, i;
  while (cin >> n) {
    f = -1;
    for (i = 1; i <= 81; i++) {
      x = sqrt(i * i / 4 + n) - i / 2;
      s = cp(x);
      if (x * x + x * s - n == 0) {
        f = x;
        break;
      }
    }
    cout << f << endl;
  }
  return 0;
}
