#include <bits/stdc++.h>
using namespace std;
long long s(long long x) {
  if (x == 0) return 0;
  long long r = 0;
  while (x) {
    r += x % 10;
    x /= 10;
  }
  return r;
}
long long F(long long x, long long k) { return x * x + k * x; }
long long bisearch(long long lo, long long hi, long long n, long long k) {
  while (lo < hi) {
    long long mid = (lo + hi) / 2.;
    if (F(mid, k) == n && s(mid) == k) {
      return mid;
    }
    if (F(mid, k) < n) {
      lo = mid + 1;
    } else {
      hi = mid;
    }
  }
  return -1.;
}
int main() {
  long long n;
  cin >> n;
  long long best = 10000000000LL;
  for (int i = 1; i <= 153; ++i) {
    int r = bisearch(0, sqrt(n) + 1, n, i);
    if (r != -1 && best > r) {
      best = r;
    }
  }
  if (best != 10000000000LL) {
    cout << best << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
