#include <stdio.h>

int main() {
  int n;
  int min;
  while (scanf ("%d\n", &n) != EOF) {
    min = 0;
    for (int i = 0; i <= n / 6 ; i++) {
      if ((n - 6 * i) % 8 == 0) {
        if (min == 0) {
          min = i + ((n - 6 * i) / 8);
        }
        if (min > i + ((n - 6 * i) / 8)) {
          min = i + ((n - 6 * i) / 8);
        }
      }
    }
    if (min == 0) {
      printf("-1\n");
    } else {
      printf("%d\n", min);
    }
  }
  return 0;
}