Biathlon
Practically all biathlon broadcasts from Vancouver began just before the race started, rarely showing the preparatory steps taken beforehand. For instance, at one checkpoint, athletes' ski equipment is inspected, while at another, their rifles are checked, and so on. There are a total of N such checkpoints. It has been determined that all biathletes can be categorized into 10 types based on the time they spend at these checkpoints. Using this information, sports scientists have developed a latency matrix of size N*10, which indicates the delay time for each type at each checkpoint.
A team of K athletes, in the order of their starting numbers, sequentially passes through each checkpoint. The first athlete begins at the first checkpoint at time 0. Once a biathlete exits checkpoint i, they join the queue for checkpoint i+1. When checkpoint j becomes available, an athlete from the queue enters it (if there is one waiting).
Your task is to determine the total time required for all athletes to pass through all the checkpoints.
Input
The first line contains the numbers N and K (1 ≤ N ≤ 1000, 1 ≤ K ≤ 10000). The next line consists of K digits without spaces, representing the types of athletes in the team. Each digit indicates the type of an athlete. The following N lines contain 10 positive numbers, each not exceeding 10000, which form the latency matrix. The i-th line specifies the time spent at checkpoint number i for athletes of types 0, 1, 2, and so on.
Output
Output a single number representing the total time required for all athletes to complete the checkpoints.