#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int r, n;
int X[maxn], Y[maxn], T[maxn];
int dp[maxn];
int pref[maxn];
int main() {
  scanf("%d %d", &r, &n);
  for (int i = 1; i <= n; i++) scanf("%d %d %d", T + i, X + i, Y + i);
  X[0] = 1, Y[0] = 1;
  dp[0] = 0, pref[0] = 0;
  for (int i = 1; i <= n; i++) {
    int pos = -1;
    for (int j = i - 1; j >= 0; j--) {
      if (T[i] - T[j] > 2 * r) {
        pos = j;
        break;
      }
      if (abs(X[i] - X[j]) + abs(Y[i] - Y[j]) > T[i] - T[j]) continue;
      if (j > 0 && !dp[j]) continue;
      dp[i] = max(dp[i], dp[j] + 1);
    }
    if (pos != -1) {
      dp[i] = max(dp[i], pref[pos] + 1);
    }
    pref[i] = max(pref[i - 1], dp[i]);
  }
  printf("%d\n", pref[n]);
  return 0;
}
