#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  for (long long int i = 1; i <= 90; i++) {
    long long int t = sqrt(i * i + 4 * n);
    if (t * t == i * i + 4 * n && t - i > 0) {
      long long int temp = (t - i) / 2, sx = 0;
      string s = to_string(temp);
      for (long long int j = 0; j < s.size(); j++)
        sx += (long long int)(s[j] - '0');
      if (sx == i) {
        cout << temp;
        return 0;
      }
    }
  }
  cout << "-1";
  return 0;
}
