#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template <class T>
bool set_max(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool set_min(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename T>
string to_string(T v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
const int N = 123;
const int MOD = 1e9 + 7;
const double eps = 1e-6;
const ll INF = 1e18;
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  int r, n;
  cin >> r >> n;
  struct Celeb {
    int t, x, y;
  };
  vector<Celeb> a(n + 1);
  vector<int> dp(n + 1, -1);
  vector<int> prefix(n + 1);
  a[0] = {0, 1, 1};
  dp[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].t >> a[i].x >> a[i].y;
    for (int j = i - 1; j >= 0; j--) {
      if (a[i].t - a[j].t >= r + r) {
        set_max(dp[i], prefix[j] + 1);
        break;
      }
      if (dp[j] != -1 &&
          a[i].t - a[j].t >= abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y)) {
        set_max(dp[i], dp[j] + 1);
      }
    }
    prefix[i] = max(prefix[i - 1], dp[i]);
  }
  cout << prefix[n] << endl;
}
