#include <bits/stdc++.h>
using namespace std;
int N, K;
int A[105];
int dp[100005][2];
int solution(int s, int p) {
  if (s == K) {
    return (p + 1) % 2;
  }
  if (dp[s][p] != -1) {
    return dp[s][p];
  }
  dp[s][p] = (p + 1) % 2;
  for (int i = 0; i < N; ++i) {
    if (s + A[i] > K) break;
    if (solution(s + A[i], (p + 1) % 2) == p) {
      dp[s][p] = p;
    }
  }
  return dp[s][p];
}
int main() {
  scanf("%d%d", &N, &K);
  for (int i = 0; i < N; ++i) scanf("%d", A + i);
  memset(dp, -1, sizeof(dp));
  printf("%d\n", solution(0, 0));
  return 0;
}
