#include <bits/stdc++.h>
using namespace std;
const long long MAX = (long long)1e5 + 55;
vector<vector<long long>> dp(MAX, vector<long long>(2, -1));
int func(long long k, long long c, vector<long long> &ar) {
  if (k <= 0) {
    return 1 - c;
  }
  if (dp[k][c] != -1) {
    return dp[k][c];
  }
  for (auto x : ar) {
    if (k >= x)
      if (func(k - x, 1 - c, ar) == c) {
        return c;
      }
  }
  return 1 - c;
}
int main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> ar(n);
  for (int x = 0; x < n; x++) {
    cin >> ar[x];
  }
  cout << func(k, 0, ar) << endl;
}
