#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
scanf("%d", &n);
int ans = 1e9, one = 1;
for(int mults = 0; mults < 16; mults++)
{
int m = n - one;
if(m >= 0 && m % 7 == 0)
{
int k = m / 7, cnt = 0;
for(int it = 0; it < mults; it++)
{
cnt += k % 4;
k /= 4;
}
cnt += k;
ans = min(ans, mults + cnt);
}
one *= 4;
}
printf("%d\n", ans == 1e9 ? -1 : ans);
return 0;
}