#include <bits/stdc++.h>
int s(int n) { return n == 0 ? 0 : s(n / 10) + n % 10; }
int main() {
  long long n;
  int x, ans;
  scanf("%lld", &n);
  ans = -1;
  for (x = (int)sqrt(n) + 1; (long long)x * (x + 81) >= n; x--)
    if ((long long)x * (x + s(x)) == n) ans = x;
  printf("%d\n", ans);
  return 0;
}
