#include <bits/stdc++.h>
using namespace std;
void file_i_o() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long int dsum(long long int n) {
  long long int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
void solve() {
  long long int n, c = 0, x = 0, s = 0;
  while (cin >> n) {
    c = -1;
    for (int i = (1); i <= (90); i++) {
      x = sqrt((((i * i) / 4) + n)) - (i / 2);
      s = dsum(x);
      if (x * x + x * s - n == 0) {
        c = x;
        break;
      }
    }
    cout << c << "\n";
  }
}
int main(int argc, char const *argv[]) {
  file_i_o();
  solve();
  return 0;
}
