#include <bits/stdc++.h>
using namespace std;
const int maxN = 5e3;
const int mod = 1e9 + 7;
int n, m, a[maxN], b[maxN];
long long dp[maxN][maxN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
  cin >> n >> m;
  memset(dp, 0, sizeof dp);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    dp[a[i]][i]++;
    if (a[i] != b[i]) {
      dp[b[i]][i + n]++;
      a[i + n] = b[i];
      b[i + n] = a[i];
    }
  }
  for (int i = 0; i <= m; i++) {
    for (int j = 0; j < 2 * n; j++) {
      for (int k = 0; k < 2 * n; k++) {
        if (!dp[i][k]) continue;
        if (b[k] == a[j] && (j % n != k % n)) dp[i + a[j]][j] += dp[i][k];
        dp[i + a[j]][j] %= mod;
      }
    }
  }
  long long res = 0;
  for (int i = 0; i < 2 * n; i++) {
    res += dp[m][i];
    res %= mod;
  }
  cout << res;
}
