"use strict";
function Main(input) {
    let N = input.split("\n")[0] - 0;
    let n = input.split("\n")[0].split("").map((v) => v - 0);
    const d = (v) => v * 100 + v * 10 + v;
    let d0 = d(n[0]);
    let d1 = d(n[1]);
    let d2 = d(n[2]);
    let n0 = Math.abs(d0 - N);
    let n1 = Math.abs(d1 - N);
    let n2 = Math.abs(d2 - N);
    let ans = [[d0, n0], [d1, n1], [d2, n2]];
    ans.sort((a, b) => a[1] - b[1]);
    if (ans[0][0] > N) ans = ans[0][0];
    else if (ans[1][0] > N) ans = ans[1][0];
    else ans = ans[2][0];
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
