public static int InputInt(string prompt)
Console.Write("Enter " + prompt + ":");
return Convert.ToInt32(Console.ReadLine());
public static int Max(int x, int y)
if(x > y) return x; else return y;
public static int Min(int x, int y)
if(x < y) return x; else return y;
public static void Main(string[] args)
int m1a = InputInt("M1 first stop");
int m1b = InputInt("M1 last stop");
int m2a = InputInt("M2 first stop");
int m2b = InputInt("M2 last stop");
int m1min = Min(m1a, m1b);
int m1max = Max(m1a, m1b);
int m2min = Min(m2a, m2b);
int m2max = Max(m2a, m2b);
int bothMin = Max(m1min, m2min);
int bothMax = Min(m1max, m2max);
nCommon = bothMax - bothMin + 1;
Console.WriteLine(nCommon.ToString());