#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T b, T p, T m) {
  T ret;
  if (p == 0) return 1;
  if (p & 1) {
    ret = (bigmod(b, p / 2, m) % m);
    return ((b % m) * ret * ret) % m;
  } else {
    ret = (bigmod(b, p / 2, m) % m);
    return (ret * ret) % m;
  }
}
template <class T>
inline T _sqrt(T a) {
  return (T)sqrt((double)a);
}
template <class T, class X>
inline T _pow(T a, X b) {
  T res = 1;
  for (int i = 1; i <= b; i++) res *= a;
  return res;
}
int dx4[] = {1, -1, 0, 0};
int dy4[] = {0, 0, 1, -1};
int dx6[] = {0, 0, 1, -1, 0, 0};
int dy6[] = {1, -1, 0, 0, 0, 0};
int dz6[] = {0, 0, 0, 0, 1, -1};
int dx8[] = {1, -1, 0, 0, -1, 1, -1, 1};
int dy8[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dkx8[] = {-1, 1, -1, 1, -2, -2, 2, 2};
int dky8[] = {2, 2, -2, -2, 1, -1, 1, -1};
int tc = 1;
const long long int mx = 500;
long long dig_sum(long long x) {
  long long ans = 0;
  while (x) ans += x % 10, x /= 10;
  return ans;
}
int main() {
  long long n, x, low, high, mid, s;
  while (cin >> n) {
    high = sqrt(n);
    low = high - mx;
    while (high >= low) {
      x = high * high + dig_sum(high) * high;
      if (x == n) break;
      high--;
    }
    if (x == n)
      cout << high << "\n";
    else
      cout << -1 << "\n";
  }
  return 0;
}
