#include <bits/stdc++.h>
int i;
int check(long long x) {
  int m = 0;
  while (x) {
    m += x % 10;
    x /= 10;
  }
  if (m == i) return 1;
  return 0;
}
int main() {
  long long n, x;
  double l;
  scanf("%I64d", &n);
  for (i = 1; i <= 81; i++) {
    x = 4 * n + i * i;
    l = sqrt(x);
    if (((long long)(l * l + 0.5) == x) && (((long long)l - i) % 2 == 0)) {
      x = ((long long)l - i) / 2;
      if (check(x)) {
        printf("%I64d\n", x);
        break;
      }
    }
  }
  if (i > 81) printf("-1\n");
}
