#include <bits/stdc++.h>
int dp[200100];
int X[200100];
int Y[200100];
int T[200100];
int MX[200100];
int main(void) {
  int n, r;
  scanf("%d %d", &r, &n);
  for (int i = 1; i <= n; i++) dp[i] = MX[i] = -200100;
  MX[0] = X[0] = Y[0] = dp[0] = T[0] = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d %d", &T[i], &X[i], &Y[i]);
    X[i]--;
    Y[i]--;
    for (int j = i - 1; j >= 0; j--) {
      if (T[i] - T[j] > r * 2) {
        dp[i] = std::max(dp[i], MX[j] + 1);
        break;
      };
      int xdiff = std::abs(X[i] - X[j]);
      int ydiff = std::abs(Y[i] - Y[j]);
      if (xdiff + ydiff <= T[i] - T[j]) {
        dp[i] = std::max(dp[i], dp[j] + 1);
      };
    };
    MX[i] = std::max(MX[i - 1], dp[i]);
  };
  printf("%d\n", MX[n]);
  return 0;
};
