#include <bits/stdc++.h>
FILE *f, *g;
long long n, rad, mx = -1, d, x, y, c, sl;
long long min(long long x, long long y) {
  if (x < y) return x;
  return y;
}
long long cif(long long x) {
  long long s = 0;
  while (x != 0) {
    s = s + (x % 10);
    x /= (long long)10;
  }
  return s;
}
int main() {
  scanf("%I64d", &n);
  n = (long long)n * 4;
  long long delta, x1;
  for (y = 1; y <= 200; y++) {
    delta = (long long)y * y + n;
    rad = (long long)sqrt(delta);
    if (rad * rad == delta) {
      x1 = (long long)(rad - y) / 2;
      if (x1 > 0 && cif(x1) == y)
        if (mx > x1 || mx == -1) mx = x1;
    }
  }
  printf("%I64d", mx);
  return 0;
}
