#!/usr/bin/env python3 INF = 10 ** 16 def main(): T = int(input()) X, A = map(int, input().split()) Y, B = map(int, input().split()) if T > 0: p, q = divmod(T, A) path1 = p * X + q # A + walk if q == 0: print(path1) return back = A - q tt, ss = divmod(back, B) if ss == 0: path2 = (p + 1) * X + tt * Y print(min(path1, path2)) else: backagain = B - ss path2 = (p + 1) * X + (tt + 1) * Y + backagain # A + B + walk print(min(path1, path2)) else: p, q = divmod(-T, B) back = B - q if q == 0: print(p) else: tt, ss = divmod(back, A) print((p + 1) * Y + tt * X + ss) return if __name__ == '__main__': main()