adding mth to last element