#include <bits/stdc++.h>
using namespace std;
long long s(long long x) {
  long long sum = 0;
  while (x) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long T;
  T = 1;
  while (T--) {
    long long n, i, x, ans = -1;
    cin >> n;
    x = sqrt(n);
    for (i = 1; i <= 90; i++) {
      long long l, r;
      l = 1;
      r = x;
      while (l <= r) {
        long long m = l + (r - l) / 2;
        long long z = m * m + m * i;
        if (z == n && s(m) == i)
          ans = m, r = m - 1;
        else if (z < n)
          l = m + 1;
        else
          r = m - 1;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
