#include <bits/stdc++.h>
using namespace std;
int a[2005], b[2005], la, lb, mod = 1e9 + 7;
int dp[2005][2005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> la >> lb;
  dp[0][0] = 1;
  for (int i = 1; i <= la; i++) cin >> a[i], dp[i][0] = 1;
  for (int i = 1; i <= lb; i++) cin >> b[i], dp[0][i] = 1;
  for (int i = 1; i <= la; i++) {
    for (int j = 1; j <= lb; j++) {
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + mod) % mod;
      if (a[i] == b[j]) dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % mod;
    }
  }
  cout << dp[la][lb];
  return 0;
}
