import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[] a = new int[m]; for (int i = 0; i < m; i++) { a[i] = sc.nextInt(); } int[][] t = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { t[i][j] = sc.nextInt(); } } sc.close(); int[] ans = new int[n]; Arrays.fill(ans, -1); List> list = new ArrayList<>(m); for (int i = 0; i < m; i++) { list.add(new ArrayList<>()); } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (ans[j] == -1) { list.get(t[j][i]).add(j); ans[j] = t[j][i]; } } for (int j = 0; j < m; j++) { List wk = list.get(j); while (wk.size() > a[j]) { int e = wk.remove(wk.size() - 1); ans[e] = -1; } } } StringBuilder sb = new StringBuilder(); for (int i : ans) { sb.append(i).append(' '); } sb.deleteCharAt(sb.length() - 1); System.out.println(sb.toString()); } }