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.*;
import java.util.*;
/*public class TaskD {

}
 */
public class TaskD implements Runnable {
	// based on Petr's template
	private void solve() throws IOException {
		ArrayList< Long > luckies = new ArrayList< Long >();
		for ( int i = 1; i <= 18; i ++ )
			for ( int mask = 0; mask < ( 1 << i ); mask ++ ){
				long num = 0;
				for ( int j = 0; j < i; j ++ ){
					num = num * 10;
					if ( ( mask & ( 1 << j ) ) != 0 )
						num += 7;
					else
						num += 4;
				}
				luckies.add( num );
			}
		long[] all = new long[ luckies.size() ];
		for ( int i = 0; i < luckies.size(); i ++ )
			all[i] = luckies.get( i );
		Arrays.sort( all );
		
		int n = this.nextInt();
		long K = this.nextLong();
		long[] l = new long[n];
		long[] r = new long[n];
		long minSeg = 1000000000000000000L;
		for ( int i = 0; i < n; i ++ ){
			l[i] = this.nextLong();
			r[i] = this.nextLong();
			minSeg = Math.min( minSeg, r[i] - l[i] + 1 );
		}
		Arrays.sort( l );
		Arrays.sort( r );
		int beg = 0;
		int end = all.length;
		int total = all.length;
		
		while( beg < end ){
			int mid = ( beg + end + 1 ) / 2;
			BigInteger left = BigInteger.valueOf(K);
			int L = 0;
			int R = 0;
			int LL = 0;
			int RR = 0;
			boolean flag = false;
//			System.out.println( mid );
			for ( int i = 0; i < n; i ++ ){
				if ( l[i] >= all[0] ){
					left = left.subtract( BigInteger.valueOf( l[i] - all[0] ) );
					LL ++;
				}
				if ( r[i] <= all[mid-1] ){
					left = left.subtract( BigInteger.valueOf( all[mid-1] - r[i] ) );
					RR ++;
				}
			}
			if ( all[mid-1] - all[0] + 1 <= minSeg && left.compareTo( BigInteger.ZERO ) >= 0 )
				flag = true;
			while( L < n && l[L] < all[0] )
				L ++;
			while( R < n && r[R] < all[mid-1] )
				R ++;
//			System.out.println( mid + " " + left + " " + LL + " " + RR + " " + L + " " + R );
			for ( int i = 1; i + mid <= total && !flag; i ++ ){
	//			System.out.println( i + " " + left + " " + LL + " " + RR + " " + L + " " + R );
				while( L < n && l[L] < all[i] ){
					left = left.subtract( BigInteger.valueOf( all[ i - 1 ] - l[L] ) );
					LL --;
					L ++;
				}
		//		System.out.println( i + " " + left + " " + LL + " " + RR + " " + L + " " + R );
				left = left.add( BigInteger.valueOf( all[i] - all[ i - 1 ] ).multiply( BigInteger.valueOf( LL ) ) );
				left = left.subtract( BigInteger.valueOf( all[i+mid-1] - all[i+mid-2] ).multiply( BigInteger.valueOf( RR ) ) );
//				System.out.println( i + " " + left + " " + LL + " " + RR + " " + L + " " + R );
				while( R < n && r[R] < all[i+mid-1] ){
					left = left.subtract( BigInteger.valueOf( all[i+mid-1] - r[R] ) );
					RR ++;
					R ++;
				}
	//			System.out.println( i + " " + left + " " + LL + " " + RR + " " + L + " " + R );
				if ( all[i+mid-1] - all[i] + 1 <= minSeg && left.compareTo( BigInteger.ZERO ) >= 0 )
					flag = true;
			}
			if ( flag )
				beg = mid;
			else
				end = mid - 1;
		}
		System.out.println( beg );
	}

	public static void main(String[] args) {
		new TaskD().run();
	}

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	public void run() {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			writer = new PrintWriter(new OutputStreamWriter(System.out));
			tokenizer = null;
			solve();
			reader.close();
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	boolean hasNext() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			String nextLine = reader.readLine();
			if (nextLine == null)
				return false;
			tokenizer = new StringTokenizer(nextLine);
		}

		return true;
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

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

	String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}

		return tokenizer.nextToken();
	}

	BigInteger nextBigInteger() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}

		return new BigInteger(tokenizer.nextToken());
	}
}