#include <bits/stdc++.h>
using namespace std;
long long n;
int s(long long n) {
  int ret = 0;
  while (n > 0) {
    ret += n % 10;
    n /= 10;
  }
  return ret;
}
int main() {
  cin.sync_with_stdio(0);
  long long sol = -1;
  cin >> n;
  for (int i = 1; i <= 90; i++) {
    long double b2 = i * i;
    long double d = sqrt(b2 + 4LL * n);
    long double x1 = (-i + d) * 0.5, x2 = (-i - d) * 0.5;
    if (x1 == floor(x1) && x1 > 0 && s(1LL * x1) == i &&
        (1LL * x1 < sol || sol == -1))
      sol = x1;
    if (x2 == floor(x2) && x2 > 0 && s(1LL * x2) == i &&
        (1LL * x2 < sol || sol == -1))
      sol = x2;
  }
  cout << sol << endl;
  return 0;
}
