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