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