#include <bits/stdc++.h>
using namespace std;
long long int digsum(long long int number) {
  long long int sum = 0;
  while (number > 0) {
    sum += number % 10;
    number /= 10;
  }
  return sum;
}
int main() {
  long long int n, i, xint, minSol = LLONG_MAX;
  double x;
  bool flag = false;
  cin >> n;
  for (i = 0; i <= 162; i++) {
    x = (((-1.0 * i) + sqrt(i * i * 1.0 + 4.0 * n)) / 2.0);
    xint = x;
    if (((xint * 1.0 - x) == 0.0) && (digsum(xint) == i) && (xint < minSol)) {
      flag = 1;
      minSol = xint;
    }
  }
  if (flag) {
    cout << minSol;
  } else {
    cout << "-1";
  }
  return 0;
}
