#include <bits/stdc++.h>
using namespace std;
long long n;
long long s(long long x) {
  long long g = 0;
  while (x > 0) {
    g += (x % 10);
    x /= 10;
  }
  return g;
}
int main() {
  cin >> n;
  long long y = sqrt(n);
  for (long long i = max(y - 90, 1ll); i <= y + 90; i++) {
    if (i * i + s(i) * i - n == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
