#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
int somaDigitos(long long x) {
  int soma = 0;
  while (x > 0) {
    soma += x % 10;
    x /= 10;
  }
  return soma;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  long long men = 1;
  long long max = 1e9;
  long long resp = LINF;
  for (int d = 1; d <= 81; d++) {
    double delta = sqrt(d * d + 4 * n);
    double val1 = (-d + delta) / 2;
    long long v = val1;
    if (v * v + v * somaDigitos(v) == n) {
      resp = min(resp, v);
    }
  }
  if (resp == LINF) {
    cout << -1 << '\n';
  } else {
    cout << resp << '\n';
  }
  return 0;
}
