import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { int n = readln.chomp.to!int - 1; size_t m = readln.chomp.to!size_t; bool[] ci = new bool[](3); ci[n] = true; foreach (_; m.iota) { int[] rd = readln.split.to!(int[]); int p = rd[0] - 1, q = rd[1] - 1; swap(ci[p], ci[q]); } int r = ci.countUntil!"a".to!int + 1; writeln(r); }