def main19():
    strbuf = input("");
    strbufs = strbuf.split();
    buf = [];
    for i in range(2):
        buf.append(int(strbufs[i]));
    if buf[0] <= buf[1] * 2:
        print((buf[1]*3));
    elif buf[0] >= buf[1] * 3:
        print(((buf[0]-buf[1])*3));
    else:
        print(buf[1]*6);





if __name__ == '__main__':
    main19()