#include <bits/stdc++.h>
using namespace std;
int invert(int player) {
  if (player == 0) return 1;
  return 0;
}
int winner(int *arr, int k, int n, int player, int **dp) {
  if (k <= 0) {
    return invert(player);
  }
  int flag = false;
  for (int i = 0; i < n; i++) {
    int ans = winner(arr, k - arr[i], n, invert(player), dp);
    if (ans == player) flag = true;
  }
  if (flag == true) return dp[k][player] = player;
  return dp[k][player] = invert(player);
}
int main() {
  int n, k;
  cin >> n >> k;
  int **dp = new int *[k + 1];
  for (int i = 0; i < k + 1; i++) {
    dp[i] = new int[2];
    for (int j = 0; j < 2; j++) dp[i][j] = -1;
  }
  int *arr = new int[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  cout << winner(arr, k, n, 0, dp) << endl;
  return 0;
}
