#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
void merge(long long *arr, long long st, long long mid, long long ed,
           long long maxele) {
  long long i = st, j = mid + 1, k = st;
  while (i <= mid && j <= ed) {
    if (arr[i] % maxele <= arr[j] % maxele) {
      arr[k] = arr[k] + (arr[i] % maxele) * maxele;
      k++;
      i++;
    } else {
      arr[k] = arr[k] + (arr[j] % maxele) * maxele;
      k++;
      j++;
    }
  }
  while (i <= mid) {
    arr[k] = arr[k] + (arr[i] % maxele) * maxele;
    k++;
    i++;
  }
  while (j <= ed) {
    arr[k] = arr[k] + (arr[j] % maxele) * maxele;
    k++;
    j++;
  }
  for (long long i = st; i < ed + 1; i++) arr[i] = arr[i] / maxele;
}
void mergeSortRec(long long *arr, long long st, long long ed,
                  long long maxele) {
  if (st >= ed) return;
  long long mid = (st + ed) / 2;
  mergeSortRec(arr, st, mid, maxele);
  mergeSortRec(arr, mid + 1, ed, maxele);
  merge(arr, st, mid, ed, maxele);
}
void mergeSort(long long *arr, long long n) {
  long long maxele = *max_element(arr, arr + n) + 1;
  mergeSortRec(arr, 0, n - 1, maxele);
}
long long fact(long long n) {
  if (n <= 1) return 1;
  return ((n % 1000000007) * (fact(n - 1) % 1000000007)) % 1000000007;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  t = 1;
  while (t--) {
    long long r, n;
    cin >> r >> n;
    long long x[n + 1], y[n + 1], t[n + 1], dp[n + 1];
    x[0] = 1, y[0] = 1, t[0] = 0;
    dp[0] = 0;
    long long ans[n + 1];
    ans[0] = 0;
    for (long long i = 1; i < n + 1; i++) {
      cin >> t[i] >> x[i] >> y[i];
      dp[i] = 0;
      ans[i] = 0;
    }
    for (long long i = 1; i < n + 1; i++) {
      for (long long j = max(i - 2 * r, (long long)0); j < i; j++) {
        if (x[j] + y[j] - 2 <= t[j] &&
            abs(x[j] - x[i]) + abs(y[j] - y[i]) <= t[i] - t[j])
          dp[i] = max(dp[i], 1 + dp[j]);
      }
      if (i >= 2 * r) dp[i] = max(dp[i], 1 + ans[i - 2 * r]);
      ans[i] = max(dp[i], ans[i - 1]);
    }
    cout << ans[n] << "\n";
  }
  return 0;
}
