#include <bits/stdc++.h>
using namespace std;
int64_t mod = 1e9 + 7;
int64_t sums(int64_t x) {
  int64_t sum = 0;
  while (x > 0) {
    sum += x % 10;
    x = x / 10;
  }
  return sum;
}
int main() {
  int64_t n;
  cin >> n;
  for (int64_t sx = 1; sx <= 90; sx++) {
    int64_t d = sx * sx + 4 * n;
    unsigned long long int sq = sqrt(d);
    if (sq * sq == d) {
      unsigned long long int x = (sq - sx) / 2;
      if (sums(x) == sx) {
        cout << x;
        return 0;
      }
    }
  }
  cout << -1;
  return 0;
}
