#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin>>n;
	if(n%8==0){
		cout<<n/8;
		return 0;
	}
	int cnt=0;
	vector<int> a;
	while(n>0){
		if(n%6==0){
			a.push_back(n/6+cnt);
		}
		n=n-8;
		cnt++;
	}
	if(a.size()==0){
		cout<<"-1";
	}
	else{
		cout<<a[a.size()-1];
	}
	return 0;
}