#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long dp[2001][2001] = {};
long long sum[2001][2001] = {};
long long calc_dp(vector<int> &s, vector<int> &t, int n, int m) {
  long long res = 1;
  for (int i = 0; i <= n; i++) {
    sum[i][0] = 1;
  }
  for (int j = 0; j <= m; j++) {
    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] % mod;
        res = (res + dp[i + 1][j + 1]) % mod;
      }
      sum[i + 1][j + 1] =
          (sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + dp[i + 1][j + 1]) % mod;
    }
  }
  return res;
}
int main() {
  long long n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> t[j];
  }
  cout << calc_dp(s, t, n, m) << endl;
  return 0;
}
