#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <typename T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int dp[2004][2004];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<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];
  dp[0][0] = 1;
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (m); ++j) {
      if (s[i] != t[j]) continue;
      int sum = 0;
      for (int k = 0; k < (i + 1); ++k)
        for (int l = 0; l < (j + 1); ++l) {
          (sum += dp[k][l]) %= (int)(1e9 + 7);
        }
      dp[i + 1][j + 1] = sum;
    }
  int ans = 0;
  for (int i = 0; i < (n + 1); ++i)
    for (int j = 0; j < (m + 1); ++j) (ans += dp[i][j]) %= (int)(1e9 + 7);
  cout << ans << endl;
}
