#include <bits/stdc++.h>
using namespace std;
int n, k0, v[102], dp[100005][2];
int game(int k, int i) {
  if (k < v[0]) return i ^ 1;
  int &ans = dp[k][i];
  if (ans != -1) return ans;
  int arr[] = {0, 0};
  for (int j = 0; j < n; ++j) {
    if (k < v[j]) break;
    ++arr[game(k - v[j], i ^ 1)];
  }
  if (arr[i])
    ans = i;
  else
    ans = i ^ 1;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(dp, -1, sizeof(dp));
  cin >> n >> k0;
  for (int i = 0; i < n; ++i) cin >> v[i];
  cout << game(k0, 0) << endl;
  return 0;
}
