// Arup Guha
// 11/11/2017
// Solution to 2017 SER D1 and D2 Problem: Treasure Map

import java.util.*;

public class treasure {

	public static int n;
	public static ArrayList[] g;
	public static mine[] mines;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		n = stdin.nextInt();
		g = new ArrayList[n];
		for (int i=0; i<n; i++) g[i] = new ArrayList<edge>();
		mines = new mine[n];
		int e = stdin.nextInt();

		// Read in the mines.
		for (int i=0; i<n; i++) {
			int gold = stdin.nextInt();
			int sub = stdin.nextInt();
			mines[i] = new mine(gold, sub);
		}

		// Add the edges to the graph.
		for (int i=0; i<e; i++) {
			int v1 = stdin.nextInt()-1;
			int v2 = stdin.nextInt()-1;
			int w = stdin.nextInt();
			g[v1].add(new edge(v2,w));
			g[v2].add(new edge(v1,w));
		}

		// State is day, mine number.
		int[][] dp = new int[1001][n];
		for (int i=0; i<=1000; i++) Arrays.fill(dp[i], -1);
		dp[0][0] = mines[0].init;
		int res = dp[0][0];

		// Go through each day.
		for (int i=0; i<=1000; i++) {
			for (int j=0; j<n; j++) {

				// Never got to this state.
				if (dp[i][j] == -1) continue;

				// Go through each edge.
				for (int k=0; k<g[j].size(); k++) {

					// Get this edge.
					edge mye = ((ArrayList<edge>)g[j]).get(k);

					// Update our dp table.
					if (i+mye.w <= 1000) {
						dp[i+mye.w][mye.to] = Math.max(dp[i+mye.w][mye.to], dp[i][j]+mines[mye.to].value(i+mye.w));
						res = Math.max(res, dp[i+mye.w][mye.to]);
					}
				}
			}
		}

		// Ta da!
		System.out.println(res);
	}
}

class mine {

	public int init;
	public int sub;

	public mine(int i, int s) {
		init = i;
		sub = s;
	}

	public int value(int d) {
		return Math.max(0, init - d*sub);
	}
}

class edge {

	public int to;
	public int w;

	public edge(int where, int weight) {
		to = where;
		w = weight;
	}
}