Simple java solution
Complexity\n- Time complexity: O(mn)\n\n- Space complexity: O(mn)\n\n# Code\n\nclass Solution {\n    public int firstCompleteIndex(int[] arr, int[][] mat) {\n  
# Complexity\n- Time complexity: $$O(m*n)$$\n\n- Space complexity: $$O(m*n)$$\n\n# Code\n```\nclass Solution {\n    public int firstCompleteIndex(int[] arr, int[][] mat) {\n        Map<Integer, int[]> nm = new HashMap<>();\n        int m=mat.length;\n        int n=mat[0].length;\n        for (int i=0;i<m;i++)\n        {\n            for (int j=0;j<n;j++)\n            {\n                nm.put(mat[i][j], new int[]{i, j});\n            }\n        }\n        int a[]=new int[m];\n        int b[]=new int[n];\n        for (int i = 0; i < arr.length; i++)\n        {\n            int c[] = nm.get(arr[i]);\n            a[c[0]]++;\n            b[c[1]]++;\n            if(a[c[0]]==n||b[c[1]]==m)\n            {\n                return i;\n            }\n        }\n        return -1;\n    }\n}\n```
['Hash Table', 'Java']