#include <bits/stdc++.h>
using namespace std;
int digits(unsigned long long int num) {
  int sum = 0;
  while (num != 0) {
    int k = num % 10;
    sum += k;
    num = num / 10;
  }
  return sum;
}
int main() {
  unsigned long long int n, i;
  cin >> n;
  int flag = 0;
  for (i = sqrt(n); i >= 1; i--) {
    if (i * i + digits(i) * i == n) {
      flag = 1;
      break;
    } else if (i * i + 90 * i < n)
      break;
  }
  if (flag == 0) {
    cout << "-1" << endl;
    return 0;
  }
  cout << i << endl;
  return 0;
}
