#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007ll;
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 i = 0; i < m; i++) cin >> t[i];
  vector<vector<long long> > dp(n, vector<long long>(m, 0ll));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i] != t[j])
        dp[i][j] = 0;
      else {
        long long sum = 1;
        for (int k = 0; k < i; k++) {
          for (int l = 0; l < j; l++) {
            sum = (sum + dp[k][l]) % MOD;
          }
        }
        dp[i][j] = sum;
      }
    }
  }
  long long ans = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans = (ans + dp[i][j]) % MOD;
    }
  }
  cout << ans << endl;
}
