#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323846;
long long int n;
long long int s(long long int x) {
  long long int s = 0;
  long long int temp = x;
  while (temp > 0) {
    s += temp % 10;
    temp /= 10;
  }
  return s;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  long long int x = sqrt(n);
  for (long long int i = x; i >= x - 1000 && i > 0; i--) {
    if (i * i + s(i) * i == n) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
