O(1)数论解法:

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        if(X == 1 || X == 2 || X == 4){
            System.out.println(-1);
            return;
        }
        int[] v = {0, 1, 2, 1, 2, 1, 2};//这是循环规律,周期长度为7
        System.out.println(X/7 + v[X%7]);
    }
}