#include <bits/stdc++.h>
using namespace std;
signed main(void) {
  long long N, M;
  long long S[2040], T[2040];
  const long long MEM = 2040;
  long long dp[MEM][MEM] = {}, sum[MEM][MEM] = {};
  cin >> N >> M;
  for (long long i = 0; i < (N); ++i) {
    cin >> S[i];
  }
  for (long long i = 0; i < (M); ++i) {
    cin >> T[i];
  }
  for (long long i = 0; i < (N); ++i) {
    for (long long j = 0; j < (M); ++j) {
      if (i != 0) {
        sum[i][j] += sum[i - 1][j];
        sum[i][j] %= 1000000007;
      }
      if (j != 0) {
        sum[i][j] += sum[i][j - 1];
        sum[i][j] %= 1000000007;
      }
      if (i != 0 && j != 0) {
        sum[i][j] -= sum[i - 1][j - 1];
        sum[i][j] %= 1000000007;
      }
      dp[i][j] += sum[i - 1][j - 1];
      dp[i][j] += 1;
      dp[i][j] %= 1000000007;
      if (S[i] != T[j]) {
        dp[i][j] = 0;
      }
      sum[i][j] += dp[i][j];
      sum[i][j] %= 1000000007;
    }
  }
  cout << (sum[N - 1][M - 1] + 1) % 1000000007 << endl;
  return 0;
}
