#include <bits/stdc++.h>
using namespace std;
long long n;
void input() { cin >> n; }
void init() {}
int GetSum(long long x) {
  int res = 0;
  while (x > 0) {
    res += (x % 10);
    x /= 10;
  }
  return res;
}
long long get_max(long long x, long long y) {
  if (x > y)
    return x;
  else
    return y;
}
void solve() {
  long long m = (long long)sqrt(n);
  for (int i = (get_max(1, m - 1000000)), _b = (m); i <= _b; i++)
    if (n % i == 0) {
      long long temp = n / i;
      if (i + GetSum(i) == temp) {
        cout << i << endl;
        return;
      }
    }
  cout << "-1" << endl;
}
void output() {}
int main() {
  clock_t timestart, timeend;
  timestart = clock();
  input();
  init();
  solve();
  output();
  timeend = clock();
  return 0;
}
