#include <bits/stdc++.h>
using namespace std;
long long sum(long long x) {
  long long res = 0;
  while (x) res += x % 10, x /= 10;
  return res;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, ans = 9e18;
  cin >> n;
  for (long long s = 1; s <= 9 * 18; ++s) {
    long double sq = sqrt(s * s + 4 * n);
    long long a = (long long)sq, b = a + 1, c = 0;
    if (a * a == s * s + 4 * n)
      c = a;
    else if (b * b == s * s + 4 * n)
      c = b;
    else
      continue;
    if ((c - s) % 2) continue;
    long long x = (c - s) / 2;
    if (sum(x) == s) ans = min(ans, x);
  }
  if (ans == 9e18) ans = -1;
  cout << ans << '\n';
  return 0;
}
