Little penguin Polo adores integer segments, that is, pairs of integers [l; r] (l ≤ r). 

He has a set that consists of n integer segments: [l1; r1], [l2; r2], ..., [ln; rn]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [l; r] to either segment [l - 1; r], or to segment [l; r + 1].

The value of a set of segments that consists of n segments [l1; r1], [l2; r2], ..., [ln; rn] is the number of integers x, such that there is integer j, for which the following inequality holds, lj ≤ x ≤ rj.

Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by k.

Input

The first line contains two integers n and k (1 ≤ n, k ≤ 105). Each of the following n lines contain a segment as a pair of integers li and ri ( - 105 ≤ li ≤ ri ≤ 105), separated by a space.

It is guaranteed that no two segments intersect. In other words, for any two integers i, j (1 ≤ i < j ≤ n) the following inequality holds, min(ri, rj) < max(li, lj).

Output

In a single line print a single integer — the answer to the problem.

Examples

Input

2 3
1 2
3 4


Output

2


Input

3 7
1 2
3 3
4 7


Output

0
import java.awt.List;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.math.BigInteger;
import java.util.StringTokenizer;

import java.util.Collections;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Random;

public class Main {

    class Input {
        BufferedReader bf;
        StringTokenizer st;

        Input(InputStream stream) throws IOException {
            bf = new BufferedReader(new InputStreamReader(stream));
            st = new StringTokenizer("");
        }

        int nextInt() throws IOException {
            if (!st.hasMoreTokens())
                st = new StringTokenizer(bf.readLine());
            
            return Integer.parseInt(st.nextToken());
        }

        long nextLong() throws IOException {
            if (!st.hasMoreTokens())
                st = new StringTokenizer(bf.readLine());
            return Long.parseLong(st.nextToken());
        }

        double nextDouble() throws IOException {
            if (!st.hasMoreTokens())
                st = new StringTokenizer(bf.readLine());
            return Double.parseDouble(st.nextToken());
        }

        void readLine() throws IOException {
            st = new StringTokenizer(bf.readLine());
        }

        String nextString() throws IOException {
            if (!st.hasMoreTokens())
                st = new StringTokenizer(bf.readLine());
            return st.nextToken();
        }

        String nextLine() throws IOException {
            return bf.readLine();
        }

        void close() throws IOException {
            bf.close();
        }
    }

    Input in;

    public class Problem {

        /*
        class Point implements Comparable<Point> {
            int x, y, p;

            Point(int a, int b, int k) {
                x = a;
                y = b;
                p = k;
            }

            @Override
            public int compareTo(Point o) {
                // TODO Auto-generated method stub
                return Integer.compare(this.x, o.x);
            }
        }*/
        
        @SuppressWarnings("deprecation")
        public void solve() throws IOException {
            /*
            int n = in.nextInt();
            int k = in.nextInt();
            if(n < k)
            {
                System.out.println(-1);
                return;
            }
            if(n == k)
            {
                char c = 'a';
                for(int i = 0; i < n; i++, c++)
                    System.out.println(c);
                return;
            }
            char[] c = new char[] { 'a', 'b' };
            int i = 0;
            boolean b = false;
            k--;
            while(n > k)
            {
                if(i == 1)
                {
                    if(!b)
                        k--;
                    b = true;
                }
                System.out.print(c[i]);
                i = (i + 1) % 2;
                n--;
            }
            char j = b ? 'c' : 'b';
            for(i = 0; i < n; i++, j++)
                System.out.print(j);
            /*
            int n = in.nextInt(), m = in.nextInt();
            int d = in.nextInt();
            
            int[][] a = new int[n][m];
            int s = 0;
            //int min = Integer.MAX_VALUE;
            //int max = Integer.MIN_VALUE;
            
            
            for(int i = 0; i < n; i++)
                for(int j = 0; j < m; j++)
                {
                    a[i][j] = in.nextInt();
                    if(a[i][j] % d != 0)
                    {
                        System.out.println(-1);
                    }
                }
            
            int lo = 0;
            int hi = 10000 / d;
            int mid;
            int res = 
            while(lo < hi)
            {
                mid = (lo + hi) / 2;
                if
                
            }
            System.out.println((max * n * m - s) / d);*/
            
            int n = in.nextInt(), m = in.nextInt();
            int a, b;
            int s = 0;
            for(int i = 0; i < n; i++)
            {
                a = in.nextInt();
                b = in.nextInt();
                s += (b - a + 1);
            }
            
            int k = s % m;
            int d = (m - k) % m;
            //int res = (k <= l) ? Math.min(k,  d) : d;
            System.out.println(d);
        
            
        }
    }


    public void solveProblem() throws IOException {
        
        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
        in = new Input(oj ? System.in : new FileInputStream("D:/Codes/Java/input.txt") );
        
        // in = new Input(System.in);
        // in = new Input(new FileInputStream("D:/Codes/Java/input.txt"));
        new Problem().solve();
        in.close();
    }

    public static void main(String[] args) throws IOException {

        new Main().solveProblem();
    }

}
