#include <bits/stdc++.h>
using namespace std;
long long gets(long long x) {
  long long sum = 0;
  while (x > 0) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}
int main() {
  long long n;
  cin >> n;
  for (long long s = 1; s <= 90; s++) {
    long long temp = sqrt(s * s + 4 * n);
    if (temp * temp == s * s + 4 * n) {
      long long x = (-s + temp) / 2;
      if (s == gets(x)) {
        cout << x;
        return 0;
      }
      x = (-s - temp) / 2;
      if (s == gets(x)) {
        cout << x;
        return 0;
      }
    }
  }
  cout << -1;
  return 0;
}
