#include <bits/stdc++.h>
const char sp = ' ';
using namespace std;
static long long dp[3000][3000];
int main(void) {
  long long N, M, S[3000], T[3000];
  cin >> N >> M;
  for (int i = 0, i_len = (N); i < i_len; ++i) cin >> S[i];
  for (int j = 0, j_len = (M); j < j_len; ++j) cin >> T[j];
  memset((dp), 0, sizeof(dp));
  dp[0][0] = 0;
  for (int i = 0, i_len = (N + 1); i < i_len; ++i)
    for (int j = 0, j_len = (M + 1); j < j_len; ++j) {
      if (i == 0 || j == 0)
        dp[i][j] = 0;
      else {
        dp[i][j] =
            (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % 1000000007;
        if (S[i - 1] == T[j - 1])
          dp[i][j] += (dp[i - 1][j - 1] + 1) % 1000000007;
        dp[i][j] %= 1000000007;
      }
    }
  cout << (dp[N][M] + 1) % 1000000007 << endl;
  return 0;
}
