#include <iostream> #include <vector> #include<algorithm> using namespace std; int main() { int N; while (cin >> N) { int count = 0; int cs[13]; const int n1 = N / 8; const int n2 = N / 6; for (int a = 0; a <= n1; a++) { for (int b = 0; b <= n2; b++) { if (8 * a + 6 * b == N) { int c = a + b; cs[count] = c; count++; } } } if (count == 0) { cout << -1 << endl; } else cout << *min_element(cs, cs + count) << endl; } return 0; }