#include <bits/stdc++.h>
using namespace std;
long long n, q, zx, xz, qw, d;
int f(int z) {
  int k = 0;
  while (z) {
    k += z % 10;
    z /= 10;
  }
  return k;
}
int main() {
  cin >> n;
  for (int i = 1; i <= 100000; i++) {
    d = i * i + 4 * n;
    if (d < 0) continue;
    qw = (long long)sqrt(d);
    if (qw * qw != d) continue;
    zx = (-i - qw);
    xz = (-i + qw);
    if (zx % 2 == 0 && f(zx / 2) == i && zx >= 0) {
      cout << zx / 2;
      return 0;
    }
    if (xz % 2 == 0 && f(xz / 2) == i && xz >= 0) {
      cout << xz / 2;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
