#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int dp[100000 + 1][2];
int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i <= a[0] - 1; i++) {
    dp[i][0] = 1;
    dp[i][1] = 0;
  }
  dp[a[0]][0] = 0;
  dp[a[0]][1] = 1;
  for (int i = a[0] + 1; i <= k; i++) {
    int flag = 1;
    for (int j = 0; j < n; j++) {
      if (i >= a[j] && dp[i - a[j]][1] == 0) {
        flag = 0;
        break;
      }
    }
    dp[i][0] = flag;
    flag = 0;
    for (int j = 0; j < n; j++) {
      if (i >= a[j] && dp[i - a[j]][0] == 1) {
        flag = 1;
        break;
      }
    }
    dp[i][1] = flag;
  }
  cout << dp[k][0];
  return 0;
}
