Java Solution 
IntuitionApproachComplexity
Time complexity: O(m∗n)

Space complexity: O(m∗n)
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity: $$O(m*n)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: $$O(m*n)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Pair {
    int x, y;

    Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }
}

class Solution {
    public int firstCompleteIndex(int[] arr, int[][] mat) {
        int m = mat.length, n = mat[0].length;

        int row[] = new int[m];
        int col[] = new int[n];

        Pair[] index = new Pair[m * n + 1];

        for(int i = 0; i < m; i++) {
            for(int j = 0; j < n; j++) {
                index[mat[i][j]] = new Pair(i, j);
            }
        }

        for(int i = 0; i < m * n; i++) {
            Pair p = index[arr[i]];

            row[p.x]++;
            col[p.y]++;

            if(row[p.x] == n || col[p.y] == m) {
                return i;
            }
        }

        return 0;
    }
}
```
['Array', 'Hash Table', 'Matrix', 'Java']