#include <bits/stdc++.h>
using namespace std;
long long SOD(long long n) {
  long long sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, ans = 99999999999999;
  cin >> n;
  for (long long i = max((long long)sqrt(n) - 100, 1LL); i < sqrt(n) + 1; i++) {
    if (i * i + SOD(i) * i - n == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
