#include <bits/stdc++.h>
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long power(long long a, long long b, long long m) {
  long long answer = 1;
  while (b) {
    if (b & 1) answer = (answer * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return answer;
}
using namespace std;
void showar(long long a[], long long n) {
  cout << "array\n";
  for (long long i = 0; i < n; i += 1) cout << a[i] << " ";
  cout << '\n';
}
void showv(vector<long long> v) {
  cout << "vector\n";
  for (long long i = 0; i < v.size(); i += 1) cout << v[i] << " ";
  cout << '\n';
}
long long x1, x2, n;
int solve(long long x) {
  long double h = sqrt(x * x + 4 * n);
  long long g = h;
  if (g != h) return -1;
  x1 = (-x + g) / 2;
  if ((-x + g) % 2) return -1;
  return 1;
}
long long sum(long long x) {
  long long second = 0;
  while (x > 0) {
    second += x % 10;
    x = x / 10;
  }
  return second;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  long long ans = 10000000000;
  for (long long i = 1; i <= 90; i++) {
    long long d = solve(i);
    if (d == -1) continue;
    if (sum(x1) == i) ans = min(ans, x1);
  }
  if (ans == pow(10, 10))
    cout << -1;
  else
    cout << ans;
  return 0;
}
