using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text;
 
public class Program
{
    public void Proc() {
        Reader.IsDebug = false;
        int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
        this.CupCount = inpt[0];
        int swapCount = inpt[1];
        for(int i=0; i<swapCount; i++) {
            int[] mv = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
            this.Move.Add(i, mv);
        }
        SetAns(0, 1, true);
        SetAns(0, 2, false);
        Console.WriteLine(ans.Count);
    }

    private int CupCount;
    private Dictionary<int, int[]> Move = new Dictionary<int, int[]>();

    private Dictionary<int, Dictionary<int, Dictionary<bool, bool>>> flags = new Dictionary<int, Dictionary<int, Dictionary<bool, bool>>>();

    private Dictionary<int, bool> ans = new Dictionary<int, bool>();

    private void SetAns(int idx, int pos, bool canMagicUse) {
        if(!flags.ContainsKey(idx)) {
            flags.Add(idx, new Dictionary<int, Dictionary<bool, bool>>());
        }
        if(!flags[idx].ContainsKey(pos)) {
            flags[idx].Add(pos, new Dictionary<bool, bool>());
        }
        if(flags[idx][pos].ContainsKey(canMagicUse)) {
            return;
        }
        flags[idx][pos][canMagicUse] = true;

        if(idx >= this.Move.Count) {
            this.ans[pos] = true;
            if(canMagicUse) {
                if(pos > 1) {
                    this.ans[pos-1] = true;
                }
                if(pos < this.CupCount) {
                    this.ans[pos+1] = true;
                }
            }
            return;
        }

        int currentPos = pos;
        if(Move[idx][0] == pos) {
            currentPos = Move[idx][1];
        } else if(Move[idx][1] == pos) {
            currentPos = Move[idx][0];
        }
        List<int> nextPos = new List<int>();
        nextPos.Add(currentPos);
        if(canMagicUse) {
            if(currentPos > 1) {
                nextPos.Add(currentPos-1);
            }
            if(currentPos < CupCount) {
                nextPos.Add(currentPos + 1);
            }
        }
        int nextIdx = this.GetNextIndex(idx, nextPos);

        this.SetAns(nextIdx, currentPos, canMagicUse);
        if(canMagicUse) {
            if(currentPos > 1) {
                this.SetAns(nextIdx,currentPos - 1, false );
            }
            if(currentPos < this.CupCount) {
                this.SetAns(nextIdx, currentPos +1, false);
            }
        }
    }

    private int GetNextIndex(int currentIdx, List<int> pos) {
        for(int i = currentIdx + 1; i<Move.Count; i++) {
            if(pos.Any(a=>Move[i].Any(b=>b==a))) {
                return i;
            }
        }
        return Move.Count;

    }
    public class Reader {
        public static bool IsDebug = true;
        private static System.IO.StringReader SReader;
        private static string InitText = @"


20 1
1 7
8 20
1 19


";
        public static string ReadLine() {
            if(IsDebug) {
                if(SReader == null) {
                    SReader = new System.IO.StringReader(InitText.Trim());
                }
                return SReader.ReadLine();
            } else {
                return Console.ReadLine();
            }
        }
    }
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 18244