#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) 
{	
	int i,j,a,b,g,x[100],y[100],mi=0,mj=0,br=0;
	int k;
//	printf("duzine matrica:\n");
	scanf("%d%d",&a,&b);
	int grad[a+1][b+1];
	for(i=1;i<=a;i++)
	{
		
		for(j=1;j<=b;j++)
		{
			scanf("%d",&grad[i][j]);
		}
	}
//	printf("unesi koliko ma slucajeva guzve\n");
	scanf("%d",&g);
	for(i=0;i<g;i++)
	{
	//	printf("guzva je na polju\n");
		scanf("%d%d",&x[i],&y[i]);
	}
	i=1;j=1;
	for(k=0;k<g;k++)
	{
	
	while (i!=a+1 && j!=b+1)
	{
		br=br+grad[i][j];
	//	printf("%d",br);
		
		if(grad[i+1][j]==NULL)
		{
			j++;
		}
		else if (grad[i][j+1]==NULL)
		{
			i++;
		}
		else
		{	if(grad[i+1][j]<grad[i][j+1])
		{
			i++;
		}
		else
		{
			j++;
		}
		
		}
	
		
	
	}}
	printf("%d",br);
	return 0;
}