# -*- coding:utf-8 -*-
class Solution:
def LastRemaining_Solution(self, n, m):
# write code here
if not n or not m or n<1 or m<1:
return -1
start=0
n=list(range(n))
while len(n)-1>0:
pop_index=(start+(m-1)%len(n))%len(n)
n.pop(pop_index)
start=pop_index
return n[0]