Filling the Grid
시간 제한1초메모리 제한1024 MB
각 행과 열이 처음부터 몇 칸까지 채워지는지 주어질 때, 이를 만족하는 격자의 수를 10^9+7로 나눈 나머지로 구한다.
문제
Suppose there is a grid consisting of empty or full cells. Let's make some definitions:
- is the number of consecutive full cells connected to the left side in the -th row (). In particular, if the leftmost cell of the -th row is empty.
- is the number of consecutive full cells connected to the top end in the -th column (). In particular, if the topmost cell of the -th column is empty.
In other words, the -th row starts exactly with full cells. Similarly, the -th column starts exactly with full cells.

These are the and values of some grid. Black cells are full and white cells are empty.
You have values of and . Initially, all cells are empty. Find the number of ways to fill grid cells to satisfy values of and . Since the answer can be very large, find the answer modulo . In other words, find the remainder after division of the answer by .
입력
The first line contains two integers and () --- the height and width of the grid.
The second line contains integers () --- the values of .
The third line contains integers () --- the values of .
출력
Print the answer modulo .
힌트
In the first example, this is the other possible case.

In the second example, it's impossible to make a grid to satisfy such , values.
In the third example, make sure to print answer modulo .