#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n + 1), t(n + 1);
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) cin >> t[i];
  long long dp[2001][2001] = {0};
  long long sum[2001][2001] = {0};
  dp[0][0] = 1;
  sum[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (s[i] == t[j])
        dp[i][j] = (sum[i - 1][j - 1] + 1) % 1000000007;
      else {
        dp[i][j] = 0;
      }
      sum[i][j] = (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] +
                   dp[i][j] + 1000000007) %
                  1000000007;
    }
  }
  cout << sum[n][m] + 1;
  return 0;
}
