#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
using ULL = unsigned long long;
using LL = long long;
long long n;
int sumOfDigits(int roots) {
  if (roots == 0) return 0;
  return roots % 10 + sumOfDigits(roots / 10);
}
void input() {
  cin >> n;
  long long x = 1e9 + 10;
  for (int sX = 0; sX <= 81; sX++) {
    long long roots = sqrt(n + sX * sX / 4.0) - sX / 2.0;
    if (roots * roots + sumOfDigits(roots) * roots == n) x = min(x, roots);
  }
  if (x == 1e9 + 10) x = -1;
  cout << x << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  input();
  return 0;
}
