#include <bits/stdc++.h>
using namespace std;
long long dp[2005][2005] = {0};
long long dp_sumCommonString(vector<int>& s, vector<int>& t) {
  for (int i = 0; i < (int)(s.size()); i++)
    for (int j = 0; j < (int)(t.size()); j++) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] + 1;
      } else {
        dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j];
      }
      dp[i + 1][j + 1] %= 1000000007;
    }
  return dp[s.size()][t.size()] + 1;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n);
  vector<int> t(m);
  for (int i = 0; i < (int)(n); i++) {
    int tmp;
    cin >> tmp;
    s[i] = tmp;
  }
  for (int j = 0; j < (int)(m); j++) {
    int tmp;
    cin >> tmp;
    t[j] = tmp;
  }
  cout << dp_sumCommonString(s, t) << endl;
}
