#include <bits/stdc++.h>
using namespace std;
long long DigitSum(long long x) {
  long long ans = 0;
  while (x > 0) {
    long long rem = x % 10;
    ans += rem;
    x /= 10;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cout.tie(NULL);
  cin.tie(NULL);
  long long n;
  cin >> n;
  for (int i = 1; i <= 90; i++) {
    long double x1 = (-i + sqrtl(i * i + 4 * n)) / 2,
                x2 = (-i - sqrtl(i * i + 4 * n)) / 2;
    long long x = x1, y = x2;
    if (x1 == x && DigitSum(x1) == i) {
      cout << x << endl;
      return 0;
    } else if (x2 == y && DigitSum(x2) == i) {
      cout << y << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
