module main; import std; void main() { auto N = readln.chomp.to!int; auto M = readln.chomp.to!int; auto cups = new bool[](4); cups[N] = true; foreach (_; 0 .. M) { int P, Q; readln.chomp.formattedRead("%d %d", P, Q); swap(cups[P], cups[Q]); } writeln(cups.countUntil(true)); }