#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1e16;
const long long MAX_N = 100010;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n), t(m);
  for (long long i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (long long i = 0; i < m; i++) {
    cin >> t[i];
  }
  vector<vector<long long>> dp(n, vector<long long>(m));
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (s[i] == t[j]) {
        for (long long x = 0; x < i; x++) {
          for (long long y = 0; y < j; y++) {
            dp[i][j] += dp[x][y];
          }
        }
        dp[i][j]++;
      }
      dp[i][j] %= mod;
    }
  }
  long long ans = 1;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      ans += dp[i][j];
      ans %= mod;
    }
  }
  cout << ans << endl;
  return 0;
}
