Pencils

Choose either set X or set Y, buy any number of copies of that one set, and pay the least to reach at least N pencils.

Easy2MathImplementationInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

JOI wants to buy NN pencils and goes to a nearby stationery shop.

The shop sells pencils only in fixed-size sets. Set XX holds AA pencils and costs BB yen. Set YY holds CC pencils and costs DD yen.

JOI picks either set XX or set YY and then buys as many copies of the chosen set as he likes. He cannot buy both kinds of set. Find the smallest amount of money needed to end up with at least NN pencils.

Input

The input is given from standard input in the following format.

N A B C D

Five integers are given on one line, separated by spaces.

Output

Print, on one line, the smallest amount of money JOI needs to get at least NN pencils.

Constraints

  • 1N10001 \le N \le 1000
  • 1A10001 \le A \le 1000
  • 1B10001 \le B \le 1000
  • 1C10001 \le C \le 1000
  • 1D10001 \le D \le 1000