Ocean Currents

题目描述

[problemUrl]: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=27&page=show_problem&problem=2620 [PDF](https://uva.onlinejudge.org/external/115/p11573.pdf) ![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA11573/d1e2b8169cdc10fcb6efb334ec4201d016849d2c.png)

输入输出格式

输入格式


![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA11573/d920afe01202359d2e8d70a7653121b90d9c46b7.png)

输出格式


![](https://cdn.luogu.com.cn/upload/vjudge_pic/UVA11573/a0f8203bb0b484bf784b764bfe0ccec8f2b61d46.png)

输入输出样例

输入样例 #1

5 5
04125
03355
64734
72377
02062
3
4 2 4 2
4 5 1 4
5 3 3 4

输出样例 #1

0
2
1