Airports

Find the minimum number of planes needed to operate all scheduled flights when planes can take repositioning flights between them.

Medium7GraphShortest pathNo attempts yetTime limit3sMemory limit256 MB

Problem

An airline operates flights out of n airports numbered 1 to n. The flight time from airport i to airport j is tijt_{ij}, and tijt_{ij} can differ from tjit_{ji} because of wind and terrain.

When a plane lands at airport i, it must be inspected for pip_i before it can take off again. The inspection time depends only on the airport where the plane lands, not on where the plane came from. A plane that lands on an extra repositioning flight is inspected the same way.

The airline must operate all m scheduled flights. Scheduled flight kk leaves airport sks_k at exactly time tkt_k and flies straight to airport fkf_k. The airline may add any number of repositioning flights to move planes around, and one plane may make several of them in a row.

A plane that operated scheduled flight aa can operate scheduled flight bb next only if it is back at airport sbs_b with its inspection finished by time tbt_b. One plane cannot operate two scheduled flights that leave at the same time.

Stated exactly: the plane that finishes flight aa is ready to take off again at Aa=ta+tsafa+pfaA_a = t_a + t_{s_a f_a} + p_{f_a}. Let dxyd_{xy} be the smallest time needed to move a plane from airport xx to airport yy, which is the minimum, over all routes, of the flight times along the route plus the inspection time at every airport where the plane lands, with dxx=0d_{xx} = 0. One plane can operate bb after aa exactly when ta<tbt_a < t_b and Aa+dfasbtbA_a + d_{f_a s_b} \le t_b.

Find the minimum number of planes needed to operate all m scheduled flights.

Input

The first line contains two space separated integers nn and mm. (1n,m5001 \le n, m \le 500)

The second line contains nn space separated integers p1,,pnp_1, \dots, p_n. (0pi1060 \le p_i \le 10^6)

Each of the next nn lines contains nn space separated integers. The jjth integer of the iith line is tijt_{ij}. (0tij1060 \le t_{ij} \le 10^6) It is guaranteed that tii=0t_{ii} = 0 for every ii, but tijt_{ij} and tjit_{ji} can differ when iji \ne j.

Each of the next mm lines contains three space separated integers sis_i, fif_i, and tit_i. (1si,fin1 \le s_i, f_i \le n, sifis_i \ne f_i, 1ti1061 \le t_i \le 10^6) It means the airline must operate a scheduled flight that leaves airport sis_i at time tit_i and flies straight to airport fif_i.

Output

Print, on a single line, the minimum number of planes needed to operate all mm scheduled flights.