#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

signed main() {
	int n,q;
	std::cin >> n >> q;
	std::map<int,int> map;
	int one = 1;
	rep(i,q) {
		rep(j,3) map[one-1+j] = 1;
		int a,b;
		std::cin >> a >> b;
		if(one==a) one = b;
		else if(one==b) one = a;
		std::swap(map[a],map[b]);
	}
	rep(j,3) map[one-1+j] = 1;
	int sum = 0;
	for(auto& i:map) {
		if(i.first==0||i.first==n+1) continue;
		sum+=i.second;
	}
	print(sum);
	return 0;
}
