a,b,n,m=map(int,input().split()) if a==b: print(a) if a>b: a -= b+1 c=a//n print(b+c) if a