#include <bits/stdc++.h>
using namespace std;
void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long sx(long long num) {
  long long sum = 0;
  while (num) {
    sum += (num % 10);
    num /= 10;
  }
  return sum;
}
int main() {
  c_p_c();
  long long n;
  cin >> n;
  for (long long i = sqrt(n); i; i--) {
    long long tmp = (n / i) - i;
    if (tmp <= 90) {
      if (tmp == sx(i)) {
        cout << i << endl;
        return 0;
      }
    } else {
      break;
    }
  }
  cout << -1 << endl;
  return 0;
}
