#include <bits/stdc++.h>
using namespace std;
bool debug = false;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long ln, lk, lm;
bool ck(long long a, int x) {
  int y = 0;
  while (a) {
    y += a % 10;
    a /= 10;
  }
  return x == y;
}
int main() {
  scanf("%lld", &ln);
  long long ans = -1;
  for (int i = 0; i <= 90; i++) {
    long long x2 = (i * i + 4 * ln);
    long long x = sqrt(x2);
    if (x * x != x2) continue;
    if (x < i || (x - i) % 2 != 0) continue;
    long long a = (x - i) / 2;
    if (ck(a, i)) {
      if (ans == -1)
        ans = a;
      else
        ans = min(a, ans);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
