import std.stdio, std.string, std.conv;
import std.algorithm, std.array;
 
immutable MOD = 1_000_000_007;

auto solve(string s_)
{
    auto NC = s_.split.map!(to!int);
    immutable N=NC[0], C=NC[1];
    immutable A = readln.split.map!(to!long).array();
    immutable B = readln.split.map!(to!long).array();
    if(A!=B) return -1;
    auto dp = new long[][](C+1,N);
    dp[0][]=1;
    foreach(c;1..C+1)
    {
        dp[c][0]=dp[c-1][0]*A[0]%MOD;
        foreach(n;1..N) dp[c][n]=(dp[c][n-1]+dp[c-1][n]*A[n])%MOD;
    }
    return dp[C][N-1];
}

void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }