// Arup Guha
// 11/8/2025
// Solution to 2025 SER D2 Problem I: Inazuma Cube Device
// Written during contest, commented later.

import java.util.*;
import java.io.*;

public class inazumacubedevice {

	public static int n;
	public static int[] scores;
	public static ArrayList<Integer>[] g;
	public static int k;
	
	public static void main(String[] args) throws Exception {
	
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tok = new StringTokenizer(stdin.readLine());
		n = Integer.parseInt(tok.nextToken());
		int numE = Integer.parseInt(tok.nextToken());
		k = Integer.parseInt(tok.nextToken());
		
		// Read the number of lit petals here.
		scores = new int[n];
		for (int i=0; i<n; i++)
			scores[i] = Integer.parseInt(stdin.readLine());
		
		// Set up our graph.
		g = new ArrayList[n];
		for (int i=0; i<n; i++)
			g[i] = new ArrayList<Integer>();
			
		// Read the graph.
		for (int i=0; i<numE; i++) {
			tok = new StringTokenizer(stdin.readLine());
			int u = Integer.parseInt(tok.nextToken())-1;
			int v = Integer.parseInt(tok.nextToken())-1;
			g[u].add(v);
		}
		
		long res = 0;
		for (int i=0; i<n; i++) {
			
			// What we must add to this one to get it done.
			int add = k-scores[i];
			
			// This means we're done actually.
			if (add == k) add = 0;
			
			// Add to our cost.
			res = res + add;
			
			// Update the scores.
			for (Integer x: g[i])
				scores[x] = (scores[x] + add)%k;
		}
		
		// Here is the result.
		System.out.println(res);
	}
}