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