#include <iostream>
#include <cstring>
using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

int s[2005];
int t[2005];

ll dp[2005][2005];
ll sum[2005][2005];

int main() {
  int n,m;
  cin >> n >> m;

  for(int i = 1; i <= n; i++) cin >> s[i];
  for(int i = 1; i <= m; i++) cin >> t[i];

  dp[0][0] = 1;
  
  for(int i = 0; i <= n; i++) sum[i][0] = 1;
  for(int i = 0; i <= m; i++) sum[0][i] = 1;
  
  for(int i = 1; i <= n; i++) {
    for(int j = 1; j <= m; j++) {
      if(s[i] == t[j]) dp[i][j] = sum[i-1][j-1];
      sum[i][j] = (sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + dp[i][j] + mod) % mod;
    }
  }

 

  cout << sum[n][m] % mod << endl;
}
