#include <bits/stdc++.h>
using namespace std;
int power(int x, unsigned int y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return power(x, y / 2) * power(x, y / 2);
  else
    return x * power(x, y / 2) * power(x, y / 2);
}
long long s(long long x) {
  long long sum = 0;
  while (x > 0) {
    sum += (x % 10);
    x /= 10;
  }
  return sum;
}
int main() {
  std::ios::sync_with_stdio(false);
  long long d, temp, n, temp1, ans, root = -1;
  cin >> n;
  for (int i = 1; i <= 100; i++) {
    d = i * i + 4 * n;
    if (d > 0) {
      temp = sqrt(d);
      if (temp * temp != d) continue;
      temp1 = -i + temp;
      if (temp1 <= 0) continue;
      if ((temp1 % 2) != 0) continue;
      ans = temp1 / 2;
      if (s(ans) == i) {
        root = ans;
        break;
      }
    }
  }
  cout << root << endl;
  return 0;
}
