# coding:utf-8 L, K = map(int,input().split()) haruka_K = K yuu_K = K nokori_L = L K_cnt = L // (haruka_K + yuu_K) nokori_L = L % (haruka_K + yuu_K) if L <= 2 * K: print(haruka_K) else: print(haruka_K * (K_cnt) + nokori_L)