#include <bits/stdc++.h>
using namespace std;
long long sod(long long x) {
  long long sum = 0;
  while (x) {
    sum += (x % 10);
    x = x / 10;
  }
  return sum;
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  long long k, n, i;
  cin >> n;
  long long x = -1;
  for (i = 1; i <= 81; i++) {
    long long t = (i * i) + (4 * n);
    long long u = sqrt(t);
    if (u * u != t) continue;
    long long num = u - i;
    if (num <= 0 || num & 1) continue;
    num = num / 2;
    if ((num * num) + (sod(num) * num) == n) {
      x = num;
      break;
    }
  }
  cout << x;
  return 0;
}
