#include <bits/stdc++.h>
using namespace std;
long long n;
long long digit_sum(long long x) {
  long long sum = 0;
  while (x) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}
int main() {
  scanf("%lld", &n);
  long long ans = -1;
  for (long long sx = 1; sx <= 90; sx++) {
    double sq1 = sqrt(sx * sx + 4 * n);
    long long sq2 = (long long)sqrt(sx * sx + 4 * n);
    long long x = (sq2 - sx) / 2;
    if ((sq1 - sq2) == 0.0) {
      if (x > 0 && digit_sum(x) == sx) {
        ans = x;
        break;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
