import std.algorithm, std.array, std.range; import std.string, std.conv; import std.stdio, std.typecons; void main() { auto n = readln.chomp.to!int - 1; auto m = readln.chomp.to!int; auto pqi = iota(m).map!(i => readln.split.map!(to!int).map!(x => x - 1)); auto ci = [false, false, false]; ci[n] = true; foreach (pq; pqi) { swap(ci[pq[0]], ci[pq[1]]); } writeln(ci.countUntil(true) + 1); }