#include <stdio.h>
int is_alternating_pattern(int *mem, int k) {
// Write your pointer logic here
int *curr = mem;
int expected = *curr; // starting value: either 0 or 1
for (int i = 0; i < k; i++) {
if (*curr != expected) {
return 0;
}
expected = 1 - expected; // alternate expectation
curr++; // move pointer forward
}
return 1;
}
int main() {
int n, k, arr[100];
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
int res = is_alternating_pattern(arr, k);
printf("%d", res);
return 0;
}