#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main() {
  int n, m;
  cin >> n >> m;
  long s[n], t[m];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> t[i];
  }
  long long dp[n + 2][m + 2];
  for (int i = 0; i < n + 2; i++) {
    for (int j = 0; j < m + 2; j++) {
      dp[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = 1 + dp[i + 1][j] + dp[i][j + 1];
        dp[i + 1][j + 1] %= MOD;
      } else {
        dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] - dp[i][j];
        dp[i + 1][j + 1] %= MOD;
      }
    }
  }
  dp[n][m] += 1;
  dp[n][m] %= MOD;
  cout << dp[n][m] << endl;
}
