/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		int[] arr = new int[]{2,4,6,6,4,2,4};
		int n = arr.length;
		
		System.out.println(helper(arr,n));
	}
	static int helper(int[] arr, int n){
		
		HashMap<Integer,Integer> map = new HashMap<>();
		int cnt = 0;
		for(int i=0;i<n;i++){
			map.put(arr[i], map.getOrDefault(arr[i],0)+1);
		}
		for(Map.Entry<Integer,Integer> entry : map.entrySet()){
			int freq = entry.getValue();
			if(freq == 1){
				return -1;
			} else {
				cnt+= freq/3+(freq%3==0?0:1);
			}
		}
		return cnt;
		
	}
}