#include <bits/stdc++.h>
using namespace std;
int s(long long x) {
  int sum = 0;
  while (x != 0) {
    sum += x % 10;
    x = x / 10;
  }
  return sum;
}
int main() {
  long long n;
  while (scanf("%lld", &n) != EOF) {
    int i;
    long long x, root = -1;
    for (i = 0; i <= 81; i++) {
      x = sqrt(n + i * i / 4) - i / 2;
      long long sx = s(x);
      if (x * x + sx * x - n == 0) {
        root = x;
        break;
      }
    }
    printf("%lld\n", root);
  }
  return 0;
}
