#include <bits/stdc++.h>
using namespace std;
int board, amount;
pair<int, int> pos[1000005];
int times[1000005];
int max_pre[1000005], max_meet[1000005];
void solve() {
  for (int i = 1; i <= amount; i++)
    if (times[i] >= pos[i].first - 1 + pos[i].second - 1) {
      max_meet[i] = max_pre[max(0, i - 1000)] + 1;
      for (int j = max(1, i - 1000); j < i; j++)
        if (times[i] - times[j] >= abs(pos[i].first - pos[j].first) +
                                       abs(pos[i].second - pos[j].second))
          max_meet[i] = max(max_meet[i], max_meet[j] + 1);
      max_pre[i] = max(max_pre[i - 1], max_meet[i]);
    } else
      max_pre[i] = max_pre[i - 1];
  printf("%d", max_pre[amount]);
}
int main() {
  scanf("%d %d", &board, &amount);
  for (int i = 1; i <= amount; i++)
    scanf("%d %d %d", &times[i], &pos[i].first, &pos[i].second);
  solve();
}
