#include <bits/stdc++.h>
int main() {
  long long n;
  while (~scanf("%I64d", &n)) {
    long long m = sqrt(n);
    long long m1 = sqrt(m);
    long long i;
    long long sum;
    int flag = 0;
    for (i = m + 1; i >= m + 1 - 100; i--) {
      sum = 0;
      long long b = i;
      while (b) {
        sum += b % 10;
        b /= 10;
      }
      long long num = sum * i + i * i;
      if (num == n) {
        printf("%I64d\n", i);
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      printf("-1\n");
    }
  }
}
