using System.Text.RegularExpressions;
public static void Main()
Console.WriteLine(f(665));
Console.WriteLine(f(665999999));
Console.WriteLine(f(666666666));
Console.WriteLine(f(66600));
public static int f(int b)
var z = new Regex("666[\\d]*");
var q = z.Replace(b+"", "667", 1);
return Int32.Parse(q.PadRight((b+"").Length, '0'));