#include <bits/stdc++.h>
using namespace std;
int s(long long x) {
  int sum = 0;
  while (x != 0) {
    sum += (x % 10);
    x /= 10;
  }
  return sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long ans = -1, x;
  for (long long i = 1; i <= (18 * 9); i++) {
    if (((long long)sqrt(i * i + 4 * n)) * ((long long)sqrt(i * i + 4 * n)) ==
        (i * i + 4 * n)) {
      x = sqrt(i * i + 4 * n);
      if (((x - i) % 2 == 0) && (((x - i) / 2) >= 1) && (i == s((x - i) / 2))) {
        ans = (x - i) / 2;
        break;
      }
    }
  }
  cout << ans;
  return 0;
}
