#include <bits/stdc++.h>
using namespace std;
int s(int x) {
  int sum = x % 10;
  while (x /= 10) sum += x % 10;
  return sum;
}
int sk(int x) {
  int sum = 9;
  while (x /= 10) sum += 9;
  return sum;
}
int main() {
  long long n, k;
  cin >> n;
  k = sqrt(n);
  int num = -1;
  while (k * (k + sk(k)) >= n) {
    if (k * (k + s(k)) == n) num = k;
    k--;
  }
  cout << num << endl;
  return 0;
}
