#include <bits/stdc++.h>
using namespace std;
int sumdigit(int n) {
  int sum = 0;
  while (n != 0) {
    sum += n % 10;
    n = n / 10;
  }
  return sum;
}
int main() {
  unsigned long long int n, b, mid;
  cin >> n;
  mid = sqrt(n);
  b = mid * mid + sumdigit(mid) * mid;
  int counter = 1;
  if (b == n) {
    cout << mid << endl;
    return 0;
  }
  if (b < n) {
    while (b <= n || counter <= 50) {
      counter++;
      mid++;
      b = mid * mid + sumdigit(mid) * mid;
      if (b == n) {
        cout << mid << endl;
        return 0;
      }
    }
    cout << -1 << endl;
    return 0;
  }
  while (b >= n || (counter <= 50 && mid > 0)) {
    counter++;
    mid--;
    b = mid * mid + sumdigit(mid) * mid;
    if (b == n) {
      cout << mid << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
