import java.io.IOException; import java.util.*; /** * Created by humac on 2017/9/7. */ public class Main { public static void main(String args[]) throws IOException {
Scanner sc=new Scanner(System.in); while (sc.hasNext()){
String s=sc.nextLine(); int n=Integer.valueOf( s.split(" ")[0]); int m=Integer.valueOf( s.split(" ")[1]); int c=Integer.valueOf( s.split(" ")[2]);
ArrayList array=new ArrayList();
String [] strs=new String[n]; for(int i=0;i<n;i++){
strs[i]=sc.nextLine();
} for (int i=0;i<n;i++){
List<String> list=new ArrayList<>(); for (int j=0;j<m;j++){ int flag=(i+j)%5;
String[] temp=strs[flag].split(" "); for (int t=1;t<temp.length;t++){ if (list.contains(temp[t])){ if(array.contains(temp[t])){ continue;
}else {
array.add(temp[t]);
}
}else {
list.add(temp[t]);
}
}
}
} if (array.contains("0")){
System.out.println(array.size()-1);
}else {
System.out.println(array.size());
}
}
}
}