#include <bits/stdc++.h>
using namespace std;
template <class T>
void smin(T &a, T b) {
  a = min(a, b);
}
template <class T>
void smax(T &a, T b) {
  a = max(a, b);
}
template <class T>
void print(vector<T> &a, string sep) {
  for (T el : a) cout << el << sep;
  cout << endl;
}
struct chash {
  int operator()(pair<int, int> x) const { return x.first * 31 + x.second; }
};
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
int dist(vector<int> &a, vector<int> &b) {
  return abs(a[0] - b[0]) + abs(a[1] - b[1]);
}
int max_el(vector<int> &a) {
  int mm = a[0];
  for (int i = 1; i < a.size(); i++) smax(mm, a[i]);
  return mm;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int r, n;
  cin >> r >> n;
  vector<long long> t(n + 1);
  vector<vector<int> > points(n + 1, vector<int>(2));
  t[0] = 0;
  points[0] = {1, 1};
  for (int i = 0; i < n; i++) {
    cin >> t[i + 1] >> points[i + 1][0] >> points[i + 1][1];
  }
  vector<int> dp(n + 1, -1);
  vector<int> maxs(n + 1);
  dp[0] = 0;
  vector<int> tl = {r, 1};
  vector<int> tr = {r, r};
  vector<int> bl = {1, 1};
  vector<int> br = {1, r};
  for (int i = 1; i <= n; i++) {
    vector<int> dists = {dist(tl, points[i]), dist(tr, points[i]),
                         dist(bl, points[i]), dist(br, points[i])};
    int t_diff = max_el(dists);
    int j = i - 1;
    while (j >= 0 && t[i] - t[j] <= t_diff) {
      if (dp[j] != -1 && dist(points[i], points[j]) <= t[i] - t[j]) {
        smax(dp[i], dp[j] + 1);
      }
      j--;
    }
    if (j >= 0 && t[i] - t[j] > t_diff) {
      smax(dp[i], maxs[j] + 1);
    }
    maxs[i] = max(maxs[i - 1], dp[i]);
  }
  cout << max_el(dp) << endl;
}
