#include <bits/stdc++.h>
using namespace std;
bool comp(pair<long long int, long long int> a,
          pair<long long int, long long int> b) {
  return a.first > b.first;
}
long long int sum(long long int n) {
  long long int sum = 0;
  while (n != 0) {
    sum = sum + (n % 10);
    n = n / 10;
  }
  return sum;
}
int main() {
  long long int n;
  cin >> n;
  long long int ans = -1;
  for (long long int i = 1; i <= 81; i++) {
    double x1 = (-i + sqrt(i * i + 4 * n)) / 2;
    if (x1 > 0 && x1 == (long long int)(x1) && i == sum(x1)) {
      ans = (long long int)x1;
      break;
    }
  }
  cout << ans;
}
