#include <bits/stdc++.h>
using namespace std;
long long _sqrt(long long x) {
  long long t = (long long)sqrt((double)x);
  if (t * t == x) return t;
  if ((t + 1) * (t + 1) == x) return t + 1;
  return -1;
}
int main() {
  long long n;
  while (~scanf("%I64d", &n)) {
    int find = 0;
    for (long long i = 1; i <= 153; i++) {
      long long t;
      if ((t = _sqrt(i * i + 4 * n)) != -1) {
        if ((t - i) & 1) continue;
        long long x = (t - i) / 2;
        long long t = x;
        long long sum = 0;
        while (t) {
          sum += t % 10;
          t /= 10;
        }
        if (sum == i) {
          printf("%I64d\n", x);
          find = 1;
          break;
        }
      }
    }
    if (!find) printf("-1\n");
  }
  return 0;
}
