#include <bits/stdc++.h>
using namespace std;
const long MOD = 1000000007;
long dp[2000][2000];
long sum[2000][2000];
int main() {
  int N, M;
  cin >> N >> M;
  int S[2001], T[2001];
  long ans = 1;
  for (int i = 0; i < N; i++) cin >> S[i];
  for (int i = 0; i < M; i++) cin >> T[i];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (S[i] == T[j]) {
        if (i == 0)
          dp[i][j] = 1;
        else if (j == 0)
          dp[i][j] = 1;
        else
          dp[i][j] = sum[i - 1][j - 1];
        dp[i][j] %= MOD;
      } else {
        dp[i][j] = 0;
      }
      if (i == 0 && j == 0)
        sum[i][j] = dp[i][j] + 1;
      else if (i == 0)
        sum[i][j] = sum[i][j - 1] + dp[i][j];
      else if (j == 0)
        sum[i][j] = sum[i - 1][j] + dp[i][j];
      else
        sum[i][j] =
            sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j];
      sum[i][j] %= MOD;
      ans += dp[i][j];
      ans %= MOD;
    }
  }
  cout << ans << endl;
}
