#include <bits/stdc++.h>
using namespace std;
const long long int INF = 99999999999999;
const long long int MOD = 1000000007;
const long long int MAX_N = 100010;
long long int a, b, c, d, e, f, x, y, z, k, m, n, l, q, h, w, t, ans = 0;
vector<long long int> v, v1, v2;
vector<pair<long long int, long long int>> p;
string s;
priority_queue<long long int> q1;
priority_queue<long long int, vector<long long int>, greater<long long int>> q2;
long long int solve() {
  long long int dp[4000][4000];
  for (long long int i = 0; i < long long int(m); i++) {
    for (long long int j = 0; j < long long int(n); j++) {
      if (i == 0 && j == 0) {
        if (v1[0] == v2[0])
          dp[0][0] = 2;
        else
          dp[0][0] = 1;
      } else if (j == 0) {
        if (v1[i] == v2[0])
          dp[i][0] = dp[i - 1][0] + 1;
        else
          dp[i][0] = dp[i - 1][0];
      } else if (i == 0) {
        if (v1[0] == v2[j])
          dp[0][j] = dp[0][j - 1] + 1;
        else
          dp[0][j] = dp[0][j - 1];
      } else {
        if (v1[i] == v2[j])
          dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % MOD;
        else
          dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1]) % MOD;
      }
    }
  }
  return dp[m - 1][n - 1];
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> m >> n;
  for (long long int i = 0; i < long long int(m); i++) {
    cin >> a;
    v1.push_back(a);
  }
  for (long long int i = 0; i < long long int(n); i++) {
    cin >> a;
    v2.push_back(a);
  }
  cout << solve() << endl;
}
