#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  scanf("%lld", &n);
  long long ans = 1000000000000000000;
  for (int i = (1); i <= (81); i += (1)) {
    long long dis = i * i + 4 * n;
    long long sdis = sqrt(dis);
    if (sdis * sdis != dis) continue;
    long long a2 = -i + sdis;
    if (a2 & 1) continue;
    a2 /= 2;
    long long s = 0, t = a2;
    while (t) {
      s += t % 10;
      t /= 10;
    }
    if (s != i) continue;
    ans = min(a2, ans);
  }
  if (ans > 1000000000)
    printf("-1\n");
  else
    printf("%lld\n", ans);
  return 0;
}
