def main():
	N, M = map(int, input().split())
	points = [[] for _ in range(N+1)]
	for i in range(1, M+1):
		a, b, c = map(int, input().split())
		points[a].append([b, c])
		points[b].append([a, c])
	is_visited = [False]*(N+1)
	is_visited[0] = True
	def dijksta(start):
		is_visited[start] = True
		stack = list(points[start])
		edge = 0
		while stack:
			edge += 1
			stack.sort(key=lambda x: x[1])
			use_edge = stack.pop()
			cur = use_edge[0]
			dist = use_edge[1]
			is_visited[cur] = True
			if all(is_visited):
				return edge
			add_stack = list(points[cur])
			removes = []
			for i, pair in enumerate(add_stack):
				if is_visited[pair[0]]:
					removes.append(i)
					continue
				pair[1] += dist
			removes.reverse()
			for i in removes:
				add_stack.pop(i)
			stack.extend(add_stack)

	ans = M - dijksta(1)
	print(ans)

if __name__ == '__main__':
    main()