#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

uint32_t dp[2001][2001] = {0};
uint32_t ss[2001] = {};
uint32_t ts[2001] = {};

static const uint32_t kRem = 1000000007;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, m; cin >> n >> m;
	FOR_LE(i, 1, n) {
		fscanf_s(stdin, "%u", &ss[i]);
	}
	FOR_LE(i, 1, m) {
		fscanf_s(stdin, "%u", &ts[i]);
	}

	FOR_LE(i, 0, n) {
		dp[i][0] = 1;
	}
	FOR_LE(j, 0, m) {
		dp[0][j] = 1;
	}

	FOR_LE(i, 1, n) {
		FOR_LE(j, 1, m) {
			uint32_t val = dp[i][j - 1];
			if (ss[i] == ts[j]) {
				val += dp[i - 1][j - 1];
			}
			val += (dp[i - 1][j] - dp[i - 1][j - 1]);

			val %= kRem;
			if (val < 0) val += kRem;
			dp[i][j] = val;
		}
	}

	printf("%d\n", dp[n][m]);

	return 0;
}