#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int r, n;
  cin >> r >> n;
  vector<array<int, 3> > a(n + 1);
  a[0] = {0, 1, 1};
  for (int i = 1; i <= n; i++) cin >> a[i][0] >> a[i][1] >> a[i][2];
  int top = 2 * r;
  int ret = 0;
  vector<int> table(n + 1, -1);
  table[0] = 0;
  int base = -1;
  for (int i = 0; i <= n; i++) {
    if (base >= 0) table[i] = max(table[i], base + 1);
    for (int j = max(0, i - top); j < i; j++) {
      if (table[j] < 0) continue;
      int d = abs(a[i][1] - a[j][1]) + abs(a[i][2] - a[j][2]);
      int dt = a[i][0] - a[j][0];
      if (dt >= d) table[i] = max(table[i], table[j] + 1);
    }
    if (i >= top) base = max(base, table[i - top]);
    ret = max(ret, table[i]);
  }
  cout << ret << "\n";
  return 0;
}
