Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Petya has n number segments [l1; r1], [l2; r2], ..., [ln; rn]. During one move Petya can take any segment (let it be segment number i) and replace it with segment [li + 1; ri + 1] or [li - 1; ri - 1]. In other words, during one move Petya can shift any segment to the left or to the right by a unit distance. Petya calls a number full if it belongs to each segment. That is, number x is full if for any i (1 ≤ i ≤ n) the condition li ≤ x ≤ ri is fulfilled.

Petya makes no more than k moves. After that he counts the quantity of full lucky numbers. Find the maximal quantity that he can get.

Input

The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 1018) — the number of segments and the maximum number of moves. Next n lines contain pairs of integers li and ri (1 ≤ li ≤ ri ≤ 1018).

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the %I64d specificator.

Output

Print on the single line the single number — the answer to the problem.

Examples

Input

4 7
1 4
6 9
4 7
3 5


Output

1


Input

2 7
40 45
47 74


Output

2

Note

In the first sample Petya shifts the second segment by two units to the left (it turns into [4; 7]), after that number 4 becomes full.

In the second sample Petya shifts the first segment by two units to the right (it turns into [42; 47]), and shifts the second segment by three units to the left (it turns into [44; 71]), after that numbers 44 and 47 become full.
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.StreamSupport;

public class D
{
	private static Comparator<long []> leftComp = new Comparator<long[]>()
	{
		@Override
		public int compare(long[] a, long[] b)
		{
			return Long.compare(a[0], b[0]);
		}
	};
	private static Comparator<long []> rightComp = new Comparator<long[]>()
	{
		@Override
		public int compare(long[] a, long[] b)
		{
			return Long.compare(a[1], b[1]);
		}
	};
	public static void main(String[] strings) throws IOException
	{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
		int n = Integer.parseInt(tokenizer.nextToken());
		long k = Long.parseLong(tokenizer.nextToken());

		long [][] leftSorted = new long[n][];
		long [][] rightSorted = new long[n][];
		long minLength = Long.MAX_VALUE;
		for(int i = 0 ; i < n ; i++)
		{
			tokenizer = new StringTokenizer(reader.readLine());
			long left = Long.parseLong(tokenizer.nextToken());
			long right = Long.parseLong(tokenizer.nextToken());

			leftSorted[i] = new long[] {left, right};
			rightSorted[i] = new long[] {left, right};
			minLength = Math.min(minLength, right-left+1);
		}

		Arrays.sort(leftSorted, leftComp);
		Arrays.sort(rightSorted, rightComp);

		long [] needStart = new long[n+1];
		double [] _needStart = new double[n+1];
		needStart[0] = 0;
		_needStart[0] = 0;
		for(int i = 0 ; i < n ; i++)
		{
			needStart[i+1] = needStart[i] + leftSorted[i][0] - leftSorted[0][0];
			_needStart[i+1] = _needStart[i] + leftSorted[i][0] - leftSorted[0][0];
		}

		long [] needEnd = new long[n+1];
		double [] _needEnd = new double[n+1];
		needEnd[n] = 0;
		_needEnd[n] = 0;
		for(int i = n-1 ; i >= 0 ; i--)
		{
			needEnd[i] = needEnd[i+1] + rightSorted[n-1][1] - rightSorted[i][1];
			_needEnd[i] = _needEnd[i+1] + rightSorted[n-1][1] - rightSorted[i][1];
		}

		TreeSet<Long> _luckyNumbers = new TreeSet<Long>();
		make(0, _luckyNumbers);

		Long [] luckyNumbers = _luckyNumbers.toArray(new Long[_luckyNumbers.size()]);

		int pLeft = 0;
		int pRight = 0;
		int res = 0;

		while(pLeft < luckyNumbers.length)
		{
			if(luckyNumbers[pRight] - luckyNumbers[pLeft] + 1 > minLength)
			{
				pLeft++;
				continue;
			}
			if(pRight < pLeft)
				pRight = pLeft;
			long need = 0;
			double _need = 0;
			int idxLeft = Arrays.binarySearch(leftSorted, new long[] {luckyNumbers[pLeft], -1}, leftComp);
			if(idxLeft < 0)
				idxLeft = -idxLeft - 1;
			need += needStart[n] - needStart[idxLeft] - (n-idxLeft)*(luckyNumbers[pLeft] - leftSorted[0][0]);
			_need += _needStart[n] - _needStart[idxLeft] - (double)(n-idxLeft)*(luckyNumbers[pLeft] - leftSorted[0][0]);

			int idxRight = Arrays.binarySearch(rightSorted, new long[] {-1, luckyNumbers[pRight]}, rightComp);
			if(idxRight < 0)
				idxRight = -idxRight - 1 - 1;
			need += needEnd[0] - needEnd[idxRight+1] - (idxRight + 1)*(rightSorted[n-1][1] - luckyNumbers[pRight]);
			_need += _needEnd[0] - _needEnd[idxRight+1] - (double)(idxRight + 1)*(rightSorted[n-1][1] - luckyNumbers[pRight]);

			if(_need < 1.5e18 && need <= k)
			{
				res = Math.max(res, pRight - pLeft+1);
				pRight++;
				if(pRight >= luckyNumbers.length)
					break;
			}
			else
				pLeft++;
		}

		System.out.println(res);
	}

	private static void make(long curr, TreeSet<Long> luckyNumbers)
	{
		luckyNumbers.add(curr+4);
		luckyNumbers.add(curr+7);
		if(curr <= 1e17)
		{
			make((curr+4)*10, luckyNumbers);
			make((curr+7)*10, luckyNumbers);
		}
	}

}