#include <bits/stdc++.h>
using namespace std;
const int N = 1e9;
long long n;
int sum(int x) {
  int s = 0;
  while (x) {
    s += x % 10;
    x /= 10;
  }
  return s;
}
int main() {
  cin >> n;
  for (int i = 0; i <= 90; i++) {
    long long sq = i * i - 4 * (-n);
    if (sq < 0) continue;
    long long d = sqrt(sq);
    if (sq == d * d) {
      long long x = (-i + d) / 2;
      if (x >= 0 && sum(x) == i) return cout << x, 0;
      x = (-i - d) / 2;
      if (x >= 0 && sum(x) == i) return cout << x, 0;
    }
  }
  cout << -1;
  return 0;
}
