#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const int mod = 999999937;
const int N = 2 * 1e5 + 10;
int cntdig(long long n) {
  int res = 0;
  while (n) {
    res += n % 10;
    n /= 10;
  }
  return res;
}
bool good(long long a, long long n) {
  if (a * (a + cntdig(a)) == n) return true;
  return false;
}
void solve() {
  long long n;
  cin >> n;
  long long a = max(0ll, (long long)sqrt(n) - 1000000);
  for (int i = 0; i < 2000000; ++i) {
    if (good(a + i, n)) {
      cout << a + i << "\n";
      return;
    }
  }
  cout << "-1\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
