#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
template <class... T>
void printl(T&&...) {}
template <class... T>
void printc(T&&...) {}
template <class... T>
void prints(T&&...) {}
struct Node {
  vector<pair<Node*, int>> dests;
  void add(Node* n, int c) { dests.emplace_back(n, c); }
  void add2(Node* n, int c) {
    add(n, c);
    n->add(this, c);
  }
  void dfs(Node* from = nullptr) {
    for (auto p : dests) {
      Node* d = p.first;
      if (d == from) {
        continue;
      }
      d->dfs(this);
    }
  }
};
struct pqElem {
  int c;
  Node* node;
  vector<pair<Node*, Node*>> froms;
  pqElem(int c, Node* d, const vector<pair<Node*, Node*>>& fs,
         pair<Node*, Node*> f = {})
      : c(c), node(d), froms(fs) {
    if (f != pair<Node*, Node*>()) {
      froms.push_back(f);
    }
  }
  bool operator<(const pqElem& p) const { return p.c > c; }
};
int main() {
  int n, m;
  cin >> n >> m;
  vector<Node> nodes(n);
  set<pair<Node*, Node*>> used;
  for (int i = 0; i < n; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    nodes[a].add2(&nodes[b], c);
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      priority_queue<pqElem> pq;
      pq.emplace(0, &nodes[i], vector<pair<Node*, Node*>>{});
      map<Node*, int> visited;
      int ans = M;
      while (pq.size()) {
        auto e = pq.top();
        pq.pop();
        int c = e.c;
        Node* n = e.node;
        if (visited.count(n) && visited[n] < c) {
          continue;
        }
        visited[n] = c;
        if (ans < c) {
          break;
        }
        if (n == &nodes[j]) {
          ans = c;
          auto& froms = e.froms;
          for (auto& f : froms) {
            if (f.first) {
              used.insert(f);
            }
          }
          continue;
        }
        for (auto p : n->dests) {
          if (n > p.first) {
            swap(n, p.first);
          }
          pq.emplace(c + p.second, p.first, e.froms, make_pair(n, p.first));
        }
      }
    }
  }
  int ans = m - used.size();
  prints([&nodes](ostream& out, Node* n) { out << n - &nodes[0]; }, used);
  cout << ans << '\n';
  return 0;
}
