using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.SplitInt();
            var N = line[0];
            var M = line[1];
            var graphBuilder = new GraphBuilder(N);
            foreach (var c in consoleReader.RepeatSplitInt(M))
                graphBuilder.Add(c[0] - 1, c[1] - 1);
            graph = graphBuilder.ToArray();

            root = Enumerable.Range(0, N).ToArray();
            for (int i = 0; i < N; i++)
            {
                SolveRoot(i);
            }
            return new HashSet<int>(root).Count;
        }
        int[][] graph;
        int[] root;
        void SolveRoot(int val)
        {
            if (root[val] == val)
                SolveRoot(val, graph[val]);
        }
        void SolveRoot(int val, int[] target)
        {
            foreach (var i in target)
            {
                if (root[i] != val)
                {
                    root[i] = val;
                    SolveRoot(val, graph[i]);
                }
            }
        }

        struct Condition
        {
            public int xi;
            public int yi;
        }

        public class GraphBuilder : IEnumerable<IList<int>>
        {
            private List<int>[] lists;
            public GraphBuilder(int count)
            {
                this.lists = new List<int>[count];
                for (int i = 0; i < count; i++)
                    this.lists[i] = new List<int>();
            }
            public void Add(int from, int to)
            {
                this.lists[from].Add(to);
                this.lists[to].Add(from);
            }

            public IEnumerator<IList<int>> GetEnumerator() => ((IEnumerable<List<int>>)this.lists).GetEnumerator();
            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => this.GetEnumerator();
            public int[][] ToArray() => this.lists.Select(l => l.ToArray()).ToArray();
        }

        public const int mod = 1000000007;
        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
        public static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

    #region Console
    public class ConsoleReader { public virtual string String() => Console.ReadLine(); public int Int() => int.Parse(String()); public long Long() => long.Parse(String()); public ulong ULong() => ulong.Parse(String()); public double Double() => double.Parse(String()); public string[] Split() => String().Split().ToArray(); public int[] SplitInt() => String().Split().Select(int.Parse).ToArray(); public long[] SplitLong() => String().Split().Select(long.Parse).ToArray(); public ulong[] SplitULong() => String().Split().Select(ulong.Parse).ToArray(); public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray(); public IEnumerable<string> Repeat(int count) { for (int i = 0; i < count; i++) yield return String(); } public IEnumerable<int> RepeatInt(int count) { for (int i = 0; i < count; i++) yield return Int(); } public IEnumerable<long> RepeatLong(int count) { for (int i = 0; i < count; i++) yield return Long(); } public IEnumerable<string[]> RepeatSplit(int count) { for (int i = 0; i < count; i++) yield return Split(); } public IEnumerable<int[]> RepeatSplitInt(int count) { for (int i = 0; i < count; i++) yield return SplitInt(); } }
    #endregion
}

Measured memory_bytes: 38548