#include <bits/stdc++.h>
using namespace std;
inline long long s(long long x) {
  long long ans = 0;
  while (x) {
    ans += (x % 10);
    x /= 10;
  }
  return ans;
}
inline long long bin(long long foo, long long bar) {
  long long l = 1, r = 1e10, ret;
  while (l <= r) {
    long long mid = (l + r) / 2;
    long long val = (mid * (mid + foo) - bar);
    if (val >= 0) {
      ret = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  return ret;
}
int main() {
  long long n;
  scanf("%lld", &n);
  long long l = bin(162, n);
  long long r = bin(1, n);
  for (long long i = l; i <= r; i++) {
    long long val = (i * i) + (i * s(i)) - n;
    if (val == 0) {
      printf("%lld\n", i);
      exit(0);
    }
  }
  puts("-1");
  return 0;
}
