Biathlon#747

Biathlon

1 second
64 megabytes
Very easy

Practically all biathlon broadcasts from Vancouver began just before the race started, rarely showing the preparations undertaken beforehand. For example, at one checkpoint, athletes' ski equipment is inspected, at another, their rifles are checked, and so on. There are a total of such checkpoints. It has been determined that all biathletes can be divided into types, based on how much time they spend at the checkpoints. Using this information, sports scientists have calculated a latency matrix of size N \times 10, which gives the delay for each type at each checkpoint.

A team of athletes, in order of their start numbers, sequentially pass through each checkpoint. The first athlete begins the check at the first checkpoint at time . Once a biathlete leaves checkpoint , they join the queue at checkpoint i+1. When checkpoint becomes available, an athlete from its queue enters (if there is someone waiting).

You need to find the total time required for all athletes to pass through all checkpoints.

Input

The first line contains the integers and (1 \le N \le 1000, 1 \le K \le 10000). The next line contains digits without spaces, describing the team composition. Each digit represents the type of an athlete. The following lines each contain positive integers, not exceeding , forming the latency matrix. The -th line shows the time spent at checkpoint for athletes of types 0, 1, \ldots, 9.

Output

Output a single integer: the total check time for all athletes.

Examples

Example 1

Loading
Loading