#!/bin/bash

read INPUT
typeset -i N=$(echo ${INPUT} | cut -d' ' -f 1 )
typeset -i X=$(echo ${INPUT} | cut -d' ' -f 2 )

if [ $(( $N % 2 )) -eq 1 ]; then
        #N is odd
        echo $(( 3 * $(( $N - 1 )) ))
else
        #N is Even
        if [ $(( $X % 2 )) -eq 1 ]; then
                #X is Odd
                if [ $(( $N - $(( 2 * $X )) )) -ge 0 ]; then
                        echo $(( 3 * $(( $N - $X )) ))
                else
                        echo $(( 3 * $X ))
                fi
        else
                #X is Even
                echo $(( 3 * $(( $N - 2 )) ))
        fi

fi
