#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int r, n;
  cin >> r >> n;
  vector<vector<int>> pos(n + 1, vector<int>(3));
  pos[0] = {0, 1, 1};
  for (int i = 0; i < n; ++i) {
    int t, h, w;
    cin >> t >> h >> w;
    pos[i + 1] = {t, h, w};
  }
  vector<int> dp(n + 1, -100000);
  dp[0] = 0;
  vector<int> ans(n + 1, 0);
  int lim = 0;
  for (int i = 1; i < n + 1; ++i) {
    while (pos[lim][0] + 2 * r <= pos[i][0]) lim++;
    for (int j = i - 1; j >= lim; --j) {
      if (pos[i][0] - pos[j][0] >=
          abs(pos[i][1] - pos[j][1]) + abs(pos[i][2] - pos[j][2])) {
        dp[i] = max(dp[i], dp[j] + 1);
      }
    }
    if (lim > 0) dp[i] = max(dp[i], ans[lim - 1] + 1);
    ans[i] = max(ans[i - 1], dp[i]);
  }
  cout << ans[n] << endl;
  return 0;
}
