#include <bits/stdc++.h>
using namespace std;
long long n;
long long ans;
int digit(long long x) {
  long long ret = 0;
  while (x) {
    ret += x % 10;
    x /= 10;
  }
  return ret;
}
int main() {
  scanf("%I64d", &n);
  ans = -1;
  for (int i = 1; i <= 81; ++i) {
    long long d = i * i + 4 * n;
    long long a = sqrt(d);
    if (a * a != d) continue;
    long long x = a - i;
    if (x <= 0 || x & 1) continue;
    x /= 2;
    if (digit(x) == i && (ans == -1 || x < ans)) ans = x;
  }
  printf("%I64d", ans);
}
