#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
const long long mod = 1e9 + 7;
const int maxn = 2e3 + 10;
int n, m;
int a[maxn];
int b[maxn];
long long dp[maxn][maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
  }
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i] == b[j]) {
        dp[i][j] = 1;
        for (int k = 1; k < i; k++) {
          for (int l = 1; l < j; l++) {
            dp[i][j] += dp[k][l];
            dp[i][j] %= mod;
          }
        }
      } else {
        dp[i][j] = 0;
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      ans += dp[i][j];
      ans %= mod;
    }
  }
  ans %= mod;
  ans += mod;
  ans %= mod;
  cout << ans << endl;
  return 0;
}
