#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);
  }
  if (dp[k] != -1) return dp[k];
  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;
  return dp[k] = 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] = -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;
}
