'use strict'

class Main {

  compare(a,b) {
    if (a == null) return -1; // a < b
    if (b == null) return 1; // b < a
    if (_.sum(a) > _.sum(b)) return 1; // b < a
    if (_.sum(b) > _.sum(a)) return -1; // a < b
    for (let i = a.length - 1;i >= 0; --i) {
      if (a[i] > b[i]) {
        return 1; // b < a
      }
      else if (b[i] > a[i]) {
        return -1; // a < b
      }
    }
    return 0;
  }

  dp(n) {
    // console.log(`call: ${n}`);
    if (n < 0) return null;
    if (this.memo[n] === undefined) {
      let ret = null;
      for (let e of this.useNums) {
        // console.log(`try ${e}`);
        let cur = null;
        if (this.count[e] == n) {
          cur = (new Array(9)).fill(0);
          cur[e] = 1;
        }
        else {
          const prev = this.dp(n - this.count[e]);
          if (prev === null) continue;
          cur = Array.from(prev);
          cur[e] = cur[e] + 1;
          // console.log(cur[e]);
        }
        if (this.compare(ret, cur) < 0) {
          ret = cur;
        }
      }
      this.memo[n] = ret;
      // console.log(`n: ${n}`);
      // console.log(ret);
      /*
      if (ret != null) {
        console.log(ret.map((e,i) => (new Array(e?e:0)).fill("123456789".charAt(i)).join('')).reverse().join(''));
      }*/
    }
    return this.memo[n];
  }

  solve() {
    const nums = input.nextIntArr();
    this.useNums = input.nextIntArr().map(e => e - 1).sort().reverse();
    // console.log(this.useNums);
    this.count = [2,5,5,4,5,6,3,7,6];
    this.memo = [];
    const numbers = Array.from("123456789");
    const result = this.dp(nums[0]);
    // console.log(result);
    console.log(result.map((e,i) => (new Array(e?e:0)).fill(numbers[i]).join('')).reverse().join(''));
  }
}

class Underscore {
  sum(arr) { return arr.reduce((a,b)=>a+b,0); }
}

class Input {
  constructor() {
    this.cursor = 0;
    this.inputAll();
  }

  inputAll() {
    this.data = (require("fs").readFileSync("/dev/stdin", "utf8")).split('\n');
    return this.data;
  }

  nextLine(n) {
    if (n) {
      const ret = this.data.slice(this.cursor, this.cursor + n);
      this.cursor += n;
      return ret;
    }
    return this.data[this.cursor++];
  }

  nextStrArr() {
    return this.nextLine().split(' ');
  }

  nextIntArr() {
    return this.nextStrArr().map((e) => parseInt(e));
  }

  nextStrRange(n) {
    return this.nextLine(n).map((line) => line.split(' '));
  }

  nextIntRange(n) {
    return this.nextLine(n).map((line) => line.split(' ').map((e) => parseInt(e)));
  }
}

const _ = new Underscore();
const input = new Input();
(new Main()).solve();
