#include <bits/stdc++.h>
using namespace std;
int cntDigits(long long a);
int main(void) {
  long long n, x;
  int s;
  cin >> n;
  for (int i = 0; i < 300; i++) {
    x = round((sqrt(i * i + 4.0 * n) - i) * 0.5);
    s = cntDigits(x);
    if (x * x + s * x == n) {
      cout << x << endl;
      return 0;
    }
  }
  puts("-1");
}
int cntDigits(long long a) {
  int sum = 0;
  while (a != 0) {
    sum += a % 10;
    a /= 10;
  }
  return sum;
}
