#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
const int MAXM = 4e6 + 10;
const long long MOD = 1e9 + 7;
const long long INF = 0x3f3f3f3f;
const unsigned long long BASE = 233;
const int base = 5;
mt19937_64 mt(time(0));
char rubbish[110];
bool GETDATA;
inline long long read() {
  long long x = 0, f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - 48;
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return x * f;
}
inline void write(long long x, char con = '\n') {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10, 0);
  putchar(x % 10 + '0');
  if (con) {
    printf("%c", con);
  }
}
long long N, M, K, Q;
pair<int, int> a[MAXN];
int t[MAXN];
long long dp[MAXN];
int dis(int i, int j) {
  return (abs(a[i].first - a[j].first) + abs(a[i].second - a[j].second));
}
void init() {
  memset(dp, 0, sizeof(dp));
  t[0] = 0;
  a[0] = {1, 1};
}
void solve() {
  long long ans = 0;
  M = read();
  N = read();
  init();
  for (int i = 1; i <= N; i++) {
    t[i] = read();
    a[i] = {read(), read()};
  }
  for (int i = 1; i <= N; i++) {
    if (dis(i, 0) > t[i]) {
      dp[i] = -1;
      continue;
    }
    for (int j = max(0LL, i - 4 * M); j < i; j++) {
      if (dis(i, j) <= t[i] - t[j]) {
        dp[i] = max(dp[i], dp[j] + 1);
      }
    }
    ans = max(ans, dp[i]);
  }
  write(ans);
}
int main() {
  int T;
  T = 1;
  for (int t = 1; t <= T; t++) {
    GETDATA = false;
    solve();
  }
  return 0;
}
