"use strict";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

!function () {
  function splitNum(line) {
    return (Array.isArray(line) ? line : line.split(/\s+/)).map(function (n) {
      return parseInt(n);
    });
  }

  var UnionFind =
  /*#__PURE__*/
  function () {
    function UnionFind(N) {
      _classCallCheck(this, UnionFind);

      this.nodes = new Array(N).fill(null).map(function () {
        return {
          parent: null,
          size: 1
        };
      });
    }

    _createClass(UnionFind, [{
      key: "find",
      value: function find(elm) {
        var node = this.nodes[elm];
        var route = [];

        for (; null != node.parent;) {
          route.push(node);
          node = node.parent;
        }

        for (var _i = 0; _i < route.length; _i++) {
          var r = route[_i];
          r.parent = node;
        }

        return node;
      }
    }, {
      key: "union",
      value: function union(elm1, elm2) {
        var node1 = this.find(elm1);
        var node2 = this.find(elm2);

        if (node1 !== node2) {
          node2.parent = node1;
          node1.size += node2.size;
          return node1;
        }
      }
    }, {
      key: "getRootNumber",
      value: function getRootNumber() {
        return this.nodes.filter(function (node) {
          return null == node.parent;
        }).length;
      }
    }]);

    return UnionFind;
  }();

  !function (input) {
    var lines = input.split("\n");

    var _splitNum = splitNum(lines[0]),
        _splitNum2 = _slicedToArray(_splitNum, 2),
        N = _splitNum2[0],
        M = _splitNum2[1];

    var infos = lines.slice(1, M + 1).map(function (line) {
      var _splitNum3 = splitNum(line),
          _splitNum4 = _slicedToArray(_splitNum3, 3),
          X = _splitNum4[0],
          Y = _splitNum4[1],
          Z = _splitNum4[2];

      return {
        X: X,
        Y: Y,
        Z: Z
      };
    });
    var uf = new UnionFind(N);
    var _iteratorNormalCompletion = true;
    var _didIteratorError = false;
    var _iteratorError = undefined;

    try {
      for (var _iterator = infos[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
        var _step$value = _step.value,
            X = _step$value.X,
            Y = _step$value.Y;
        uf.union(X - 1, Y - 1);
      }
    } catch (err) {
      _didIteratorError = true;
      _iteratorError = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion && _iterator.return != null) {
          _iterator.return();
        }
      } finally {
        if (_didIteratorError) {
          throw _iteratorError;
        }
      }
    }

    console.log(uf.getRootNumber());
  }(require("fs").readFileSync("/dev/stdin", "utf8"));
}();
