#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vin = vector<int>;
using vll = vector<long long>;
using vvin = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using vstr = vector<string>;
using vvstr = vector<vector<string>>;
using vch = vector<char>;
using vvch = vector<vector<char>>;
using vbo = vector<bool>;
using vvbo = vector<vector<bool>>;
using vpii = vector<pair<int, int>>;
using pqsin = priority_queue<int, vector<int>, greater<int>>;
const ll inf = 1e9 + 7;
const ll INF = 1e18;
int main() {
  int n, m;
  cin >> n >> m;
  vin s(n), t(m);
  for (int i = 0; i < (int)(n); i++) cin >> s[i];
  for (int i = 0; i < (int)(m); i++) cin >> t[i];
  vvll dp(n + 1, vll(m + 1, (ll)1));
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(m); j++) {
      dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] - dp[i][j];
      if (s[i] == t[j]) dp[i + 1][j + 1] += dp[i][j];
      dp[i + 1][j + 1] %= inf;
    }
  cout << (dp[n][m]) % inf << endl;
}
