#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <class T>
inline void amin(T &x, const T &y) {
  if (y < x) x = y;
}
template <class T>
inline void amax(T &x, const T &y) {
  if (x < y) x = y;
}
template <class Iter>
void rprintf(const char *fmt, Iter begin, Iter end) {
  for (bool sp = 0; begin != end; ++begin) {
    if (sp)
      putchar(' ');
    else
      sp = true;
    printf(fmt, *begin);
  }
  putchar('\n');
}
int N;
int T[100011];
int X[100011];
int Y[100011];
int val[100011];
void MAIN() {
  int R;
  scanf("%d%d", &R, &N);
  for (int i = 0, i_len = (N); i < i_len; ++i)
    scanf("%d%d%d", T + i, X + i, Y + i);
  const int INF = 1 << 29;
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    val[i] = -INF;
    if (X[i] + Y[i] - 2 <= T[i]) val[i] = 1;
    for (int j = i - 1; j >= 0; j--) {
      if (abs(X[i] - X[j]) + abs(Y[i] - Y[j]) <= T[i] - T[j]) {
        amax(val[i], val[j] + 1);
      }
      if (T[i] - T[j] > 2000) break;
    }
  }
  int ans = 0;
  for (int i = 0, i_len = (N); i < i_len; ++i) amax(ans, val[i]);
  printf("%d\n", ans);
}
int main() {
  int TC = 1;
  for (int tc = 0, tc_len = (TC); tc < tc_len; ++tc) MAIN();
  return 0;
}
