#include <bits/stdc++.h>
using namespace std;
struct guy {
  int x;
  int y;
  int t;
};
int r, n;
vector<guy> arr;
vector<int> dp;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> r >> n;
  arr = vector<guy>(n);
  dp = vector<int>(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> arr[i].t >> arr[i].x >> arr[i].y;
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = i + 1; j < min(n, i + 4 * r); j++) {
      if (abs(arr[j].y - arr[i].y) + abs(arr[j].x - arr[i].x) <=
          arr[j].t - arr[i].t)
        dp[i] = max(dp[i], 1 + dp[j]);
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (abs(1 - arr[i].y) + abs(1 - arr[i].x) <= arr[i].t) {
      ans = max(ans, 1 + dp[i]);
    }
  }
  cout << ans << "\n";
  return 0;
}
