Start by simplifying that: Create a List Of String and populate it with the Subject values from the first DataGridView - that's a trivial For Each loop.
When you have that, you can use the Linq Contains method to check if the list contains each value:
Enumerable.Contains(TSource) Method (IEnumerable(TSource), TSource) (System.Linq)[
^] - it returns a Boolean which you can use to set the value of your Mark column directly.
That way, you don't need to nest the loops, and you process N1 + N2 loops, instead of N1 * N2