#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/detail/ceil_and_floor.hpp
#ifndef DETAIL_CEIL_AND_FLOOR_HPP
#define DETAIL_CEIL_AND_FLOOR_HPP

namespace tools {
  template <typename T>
  constexpr T floor(T lhs, T rhs);

  template <typename T>
  constexpr T ceil(T lhs, T rhs);

  template <typename T>
  constexpr T floor(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        lhs / rhs :
      lhs < 0 && rhs >= 0 ?
        -ceil<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -ceil<T>(lhs, -rhs) :
        floor<T>(-lhs, -rhs);
  }

  template <typename T>
  constexpr T ceil(const T lhs, const T rhs) {
    return
      lhs >= 0 && rhs >= 0 ?
        (lhs - 1 + rhs) / rhs :
      lhs < 0 && rhs >= 0 ?
        -floor<T>(-lhs, rhs) :
      lhs >= 0 && rhs < 0 ?
        -floor<T>(lhs, -rhs) :
        ceil<T>(-lhs, -rhs);
  }
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// lib/ceil.hpp
#ifndef CEIL_HPP
#define CEIL_HPP


/*
usage:

tools::ceil(5, 3) // => 2 (i.e., ceil(5 / 3))
*/

#endif

// main.cpp

std::array<i64, 6> calc_next_p(const std::array<i64, 6>& p, const std::array<i64, 5>& flows) {
  return std::array<i64, 6>({
    p[0] - flows[0],
    p[1] + flows[0] - flows[1],
    p[2] + flows[1] - flows[2],
    p[3] + flows[2] - flows[3],
    p[4] + flows[3] - flows[4],
    p[5] + flows[4]
  });
}

int main() {
  i64 N, A, B, C, D, E;
  std::cin >> N >> A >> B >> C >> D >> E;

  std::array<i64, 6> p = {N, 0, 0, 0, 0, 0};
  i64 answer = 0;

  {
    const i64 t = tools::ceil<i64>(p[0], A);
    const std::array<i64, 5> flows = {
      p[0],
      std::max<i64>(t - std::max<i64>(1 - answer, 0), 0) * std::min(A, B),
      std::max<i64>(t - std::max<i64>(2 - answer, 0), 0) * std::min({A, B, C}),
      std::max<i64>(t - std::max<i64>(3 - answer, 0), 0) * std::min({A, B, C, D}),
      std::max<i64>(t - std::max<i64>(4 - answer, 0), 0) * std::min({A, B, C, D, E})
    };
    p = calc_next_p(p, flows);
    answer += t;
  }

  {
    const i64 t = tools::ceil<i64>(p[1], B);
    const std::array<i64, 5> flows = {
      0,
      p[1],
      std::max<i64>(t - std::max<i64>(2 - answer, 0), 0) * std::min({A, B, C}),
      std::max<i64>(t - std::max<i64>(3 - answer, 0), 0) * std::min({A, B, C, D}),
      std::max<i64>(t - std::max<i64>(4 - answer, 0), 0) * std::min({A, B, C, D, E})
    };
    p = calc_next_p(p, flows);
    answer += t;
  }

  {
    const i64 t = tools::ceil<i64>(p[2], C);
    const std::array<i64, 5> flows = {
      0,
      0,
      p[2],
      std::max<i64>(t - std::max<i64>(3 - answer, 0), 0) * std::min({A, B, C, D}),
      std::max<i64>(t - std::max<i64>(4 - answer, 0), 0) * std::min({A, B, C, D, E})
    };
    p = calc_next_p(p, flows);
    answer += t;
  }

  {
    const i64 t = tools::ceil<i64>(p[3], D);
    const std::array<i64, 5> flows = {
      0,
      0,
      0,
      p[3],
      std::max<i64>(t - std::max<i64>(4 - answer, 0), 0) * std::min({A, B, C, D, E})
    };
    p = calc_next_p(p, flows);
    answer += t;
  }

  {
    const i64 t = tools::ceil<i64>(p[4], E);
    const std::array<i64, 5> flows = {
      0,
      0,
      0,
      0,
      p[4]
    };
    p = calc_next_p(p, flows);
    answer += t;
  }

  assert(p[5] == N);
  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 256