#include <bits/stdc++.h>
int main() {
  int point_numbers = 0, side = 0;
  scanf("%d %d", &point_numbers, &side);
  struct point {
    int xt;
    int yt;
    char color;
  };
  struct point *information =
      (struct point *)malloc(point_numbers * sizeof(struct point));
  for (int i = 0; i < point_numbers; i++) {
    scanf("%d", &(information[i].xt));
    scanf("%d", &(information[i].yt));
    scanf("%c", &(information[i].color));
  }
  int max_fit_point_numbers = 0;
  int x = 1;
  int y = 1;
  for (int r = 0; r <= side; r++) {
    for (int u = 0; u <= side; u++) {
      int fit_point_numbers = 0;
      for (int i = 0; i < point_numbers; i++) {
        if ((abs(information[i].xt - x) % 6 <= 1) &&
            (abs(information[i].yt - y) % 6 <= 1) &&
            (information[i].color == 'B')) {
          fit_point_numbers++;
        } else if ((abs(information[i].xt - x) % 6 >= 2 &&
                    (abs(information[i].xt - x) % 6 <= 4)) &&
                   (abs(information[i].yt - y) % 6 >= 2 &&
                    (abs(information[i].yt - y) % 6 <= 4)) &&
                   (information[i].color == 'B')) {
          fit_point_numbers++;
        } else if ((abs(information[i].xt - x) % 6 >= 2 &&
                    (abs(information[i].xt - x) % 6 <= 4)) &&
                   (abs(information[i].yt - y) % 6 <= 1) &&
                   (information[i].color == 'W')) {
          fit_point_numbers++;
        } else if ((abs(information[i].xt - x) % 6 <= 1) &&
                   (abs(information[i].yt - y) % 6 >= 2 &&
                    (abs(information[i].yt - y) % 6 <= 4)) &&
                   (information[i].color == 'W')) {
          fit_point_numbers++;
        }
      }
      if (fit_point_numbers > max_fit_point_numbers) {
        max_fit_point_numbers = fit_point_numbers;
      }
    }
  }
  printf("%d", max_fit_point_numbers);
  free(information);
  return 0;
}
