#include <bits/stdc++.h>
using namespace std;
long long n;
int sum_d(int x) {
  int sum = 0;
  while (x > 0) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}
long long f(long long x, long long sumd) { return x * (x + sumd) - n; }
long long search(long long sumd) {
  long long lo = 1, hi = 1e9;
  while (hi - lo > 0) {
    long long mi = lo + (hi - lo) / 2;
    if (f(mi, sumd) >= 0)
      hi = mi;
    else
      lo = mi + 1;
  }
  if (f(lo, sumd) == 0) return lo;
  return -1;
}
int main() {
  cin >> n;
  long long mini = 1e9;
  for (int sumd = 1; sumd <= 100; sumd++) {
    long long x = search(sumd);
    if (x != -1 && sumd == sum_d(x)) mini = min(mini, x);
  }
  if (mini == 1e9)
    cout << "-1";
  else
    cout << mini;
  return 0;
}
