#include <bits/stdc++.h>
using namespace std;
bool check(long long n, long long s) {
  long long sum = 0;
  while (n) {
    sum += n % 10;
    n /= 10;
  }
  return sum == s;
}
int main() {
  long long n, s, rt, ans = -1;
  cin >> n;
  for (s = 1; s < 100; s++) {
    rt = sqrt(s * s + 4 * n);
    if (rt * rt == s * s + 4 * n) {
      if ((rt - s) % 2 == 0) {
        if (check((rt - s) / 2, s)) {
          if (ans == -1)
            ans = (rt - s) / 2;
          else
            ans = min(ans, (rt - s) / 2);
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
