#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}
long long int dp[2001][2001];
long long int sdp[2001][2001];
const long long int mod = 1000000007;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
  int n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  cin >> s;
  cin >> t;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i] == t[j]) {
        dp[i][j] = 1;
        for (int k = 0; k < i; k++)
          for (int l = 0; l < j; l++) dp[i][j] = (dp[i][j] + dp[k][l]) % mod;
      }
    }
  }
  long long int ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) ans = (ans + dp[i][j]) % mod;
  cout << ans + 1 << endl;
  return 0;
}
