#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
long long S(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 <= 162; s += 1LL) {
    double r = sqrt((double)(s * s + 4 * n));
    if (r - (long long)r == 0.0) {
      if (((long long)r - s) % 2 == 0) {
        long long x = (r - s) / 2;
        if (x > 0 && S(x) == s) {
          cout << x << endl;
          return 0;
        }
      }
    }
  }
  puts("-1");
}
