#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
long long n, m, s[2009], t[2009], dp[2009][2009];
void solve() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i] == t[j]) {
        if (i == 0) {
          if (j == 0) {
            dp[i][j] = 1;
          } else {
            dp[i][j] = (dp[i][j - 1] + 1) % MOD;
          }
        } else {
          if (j == 0) {
            dp[i][j] = (dp[i - 1][j] + 1) % MOD;
          } else {
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] + 1) % MOD;
          }
        }
      } else {
        if (i == 0) {
          if (j == 0) {
            dp[i][j] = 0;
          } else {
            dp[i][j] = dp[i][j - 1];
          }
        } else {
          if (j == 0) {
            dp[i][j] = dp[i - 1][j];
          } else {
            dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1]) % MOD;
          }
        }
      }
    }
  }
  cout << (dp[n - 1][m - 1] + 1) % MOD << endl;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> t[i];
  }
  solve();
}
