using System;
using System.Collections.Generic;

namespace Aleksa1
{
    class Program
    {
        static List<List<int>> sviMoguciPutevi = new List<List<int>>();

        static void Main(string[] args)
        {
            var dimenzijeGrada = Console.ReadLine().Split();
            var n = int.Parse(dimenzijeGrada[0]);
            var m = int.Parse(dimenzijeGrada[1]);

            var doha = new List<List<int>>();
            for (int i = 0; i < n; i++)
            {
                var nav = new List<int>();
                var navijaciUlaz = Console.ReadLine().Split();
                for (int x = 0; x < m; x++)
                {
                    nav.Add(int.Parse(navijaciUlaz[x]));
                }
                doha.Add(nav);
            }

            var blokade = new List<(int, int)>();
            int q = int.Parse(Console.ReadLine());
            for (int i = 0; i < q; i++)
            {
                var blokadaUlaz = Console.ReadLine().Split();
                blokade.Add((int.Parse(blokadaUlaz[0]), int.Parse(blokadaUlaz[1])));
            }

            sviPutevi(doha, n, m, blokade);

            int minBrojNavijaca = -1;
            for (int i = 0; i < sviMoguciPutevi.Count; i++)
            {
                var path = sviMoguciPutevi[i];
                var brojNavijaca = 0;
                foreach (var x in path)
                {
                    brojNavijaca += x;
                }

                if (minBrojNavijaca == -1 || minBrojNavijaca > brojNavijaca)
                {
                    minBrojNavijaca = brojNavijaca;
                }
            }

            Console.WriteLine(minBrojNavijaca);
        }

        static void sviPutevi(List<List<int>> doha, int m, int n, List<(int, int)> blokade)
        {
            var path = new List<int>();
            for (int i = 0; i < m + n - 1; i++)
            {
                path.Add(0);
            }
            nadjiPut(doha, m, n, 0, 0, path, 0, blokade);
        }

        static void nadjiPut(List<List<int>> doha, int m, int n, int i, int j, List<int> put, int index, List<(int, int)> blokade)
        {
            if (blokade.Contains((i, j)))
            {
                return;
            }

            if (i == m - 1)
            {
                for (int k = j; k < n; k++)
                {
                    put[index + k - j] = doha[i][k];
                }

                var noviPut = new List<int>();
                noviPut.Add(put[0]);
                for (int z = 1; z < put.Count - 1; z++)
                {
                    noviPut.Add(put[z]);
                }
                noviPut.Add(put[put.Count - 1]);
                sviMoguciPutevi.Add(noviPut);
                return;
            }

            if (j == n - 1)
            {
                for (int k = i; k < m; k++)
                {
                    put[index + k - i] = doha[k][j];
                }

                var newPath = new List<int>();
                var newPathInd = new List<(int, int)>();
                newPath.Add(put[0]);
                for (int z = 1; z < put.Count - 1; z++)
                {
                    newPath.Add(put[z]);
                }
                newPath.Add(put[put.Count - 1]);
                sviMoguciPutevi.Add(newPath);
                return;
            }

            put[index] = doha[i][j];

            nadjiPut(doha, m, n, i + 1, j, put, index + 1, blokade);

            nadjiPut(doha, m, n, i, j + 1, put, index + 1, blokade);
        }
    }
}