#include <bits/stdc++.h>
using namespace std;

int m, n;
int s[2000];
int t[2000];
long DP[2001][2001];
const long mod = 1000000007;
int main() {
  cin >> m >> n;
  for (int i = 0; i < m; ++i) cin >> s[i];
  for (int j = 0; j < n; ++j) cin >> t[j];
  for (int i = 0; i <= m; ++i) {
    for (int j = 0; j <= n; ++j) {
      if (i == 0 || j == 0) {
        DP[i][j] = 1;
      } else {
        DP[i][j] = DP[i - 1][j] + DP[i][j - 1] + mod - DP[i - 1][j - 1];
        if (s[i - 1] == t[j - 1]) {
          DP[i][j] += DP[i - 1][j - 1];
        }
        DP[i][j] %= mod;
      }
    }
  }
  cout << DP[m][n] << endl;
}