#include <iostream>
using namespace std;

int main() {
    int a;
    while (cin >> a) { // 注意 while 处理多个 case
       for(int i=0;i<=a/6;i++)
       {
        for(int j=0;j<=a/8;j++){
            if(a==(6*i+8*j)){
                cout<<i+j;
                 return 0;
            }
        }
       }
       cout<<-1;
       return 0;
    }
}
// 64 位输出请用 printf("%lld")