#include <bits/stdc++.h>
using namespace std;
long long n, ans, l;
bool flag = 0;
inline long long getLen(long long x) {
  long long cnt = 0;
  while (x) {
    cnt++;
    x /= 10;
  }
  return cnt;
}
inline long long getSum(long long x) {
  long long cnt = 0;
  while (x) {
    cnt += x % 10;
    x /= 10;
  }
  return cnt;
}
int main() {
  cin >> n;
  long long sqn = sqrt(n);
  for (l = sqn; l > 0; l--) {
    if (l * l + 9 * l * getLen(l) < n) break;
  }
  for (ans = l; ans <= sqn; ans++) {
    if (ans * ans + ans * getSum(ans) == n) {
      flag = 1;
      break;
    }
  }
  printf("%lld\n", flag ? ans : -1);
  return 0;
}
