#include <bits/stdc++.h>
using namespace std;
int s(long long x) { return x < 10 ? x : x % 10 + s(x / 10); }
int main() {
  long long n;
  cin >> n;
  long long nn = sqrt(n);
  for (long long x = max(nn - 1000000, 1LL); x < nn + 1000000; x++) {
    if (x * x + s(x) * x - n == 0) return cout << x << endl, 0;
  }
  return cout << -1 << endl, 0;
}
