#include <bits/stdc++.h>
using namespace std;
long long n;
long long s(long long x) {
  long long res = 0;
  while (x) {
    res += x % 10;
    x /= 10;
  }
  return res;
}
signed main() {
  long long n, i;
  cin >> n;
  if (sqrt(n) - 100 > 0)
    i = sqrt(n) - 100;
  else
    i = 1;
  for (; i <= sqrt(n); i++)
    if (i * i + s(i) * i == n) {
      cout << i;
      return 0;
    }
  cout << -1;
}
