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.*;
import java.util.Random;

import static java.lang.Math.*;

public class Solution implements Runnable {

	public static void main(String[] args) throws Exception {
		new Thread(null, new Solution(), "", 1 << 25).start();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;

	final String fname = "";
	
	private String next() throws Exception {
		if (st == null || !st.hasMoreElements())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

	private int nextInt() throws Exception {
		return Integer.parseInt(next());
	}

	private long nextLong() throws Exception {
		return Long.parseLong(next());
	}

	private double nextDouble() throws Exception {
		return Double.parseDouble(next());
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
			solve();
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		} finally {
			out.close();
		}
	}
	
	void rec(long num) {
		if (num>1000000000000000000L) {
			return;
		}
		if (num!=0) {
			lucky.add(num);
		}
		rec(num*10+4);
		rec(num*10+7);
	}
	
	class Segment {
		long l,r;
		int index;
		public Segment(long l,long r,int index) {
			this.l=l;
			this.r=r;
			this.index=index;
		}
	}
	
	ArrayList<Long> lucky = new ArrayList<Long>();
	
	class FenwickTreeBig {
		int n;
		BigInteger t[];
		
		BigInteger sum(int r) {
			BigInteger result=BigInteger.ZERO;
			for (; r>=0; r=(r & (r+1))-1)
				result=result.add(t[r]);
			return result;
		}
		
		BigInteger sum(int l,int r) {
			return sum(r).subtract(sum(l-1));
		}
		
		void inc (int i,long delta) {
			for (; i<n; i = (i | (i+1)))
				t[i]=t[i].add(BigInteger.valueOf(delta));
		}
		
		
		public FenwickTreeBig(int n) {
			this.n=n;
			t = new BigInteger[n];
			Arrays.fill(t, BigInteger.ZERO);
		}
	}
	
	class FenwickTreeInteger {
		int n;
		int t[];
		
		int sum(int r) {
			int result=0;
			for (; r>=0; r=(r & (r+1))-1)
				result+=t[r];
			return result;
		}
		
		int sum(int l,int r) {
			return sum(r)-sum(l-1);
		}
		
		void inc (int i,int delta) {
			for (; i<n; i = (i | (i+1)))
				t[i]+=delta;
		}
		
		public FenwickTreeInteger(int n) {
			this.n=n;
			t = new int [n];
		}
		
	}
	
	ArrayList<Segment> a = new ArrayList<Segment>();
	ArrayList<Segment> rights = new ArrayList<Solution.Segment>();
	
	int indexright [];
	
	public void solve() throws Exception {
		int n=nextInt();
		long k=nextLong();
		FenwickTreeBig leftsum = new FenwickTreeBig(n);
		FenwickTreeInteger leftcount = new FenwickTreeInteger(n);
		indexright = new int [n];
		for (int i=0;i<n;i++) {
			a.add(new Segment(nextLong(),nextLong(),i));
		}
		rec(0);
		Collections.sort(lucky);
		Collections.sort(a, new Comparator<Segment>() {
			@Override
			public int compare(Segment o1, Segment o2) {
				if (o1.r<o2.r) return -1;
				if (o1.r>o1.r) return 1;
				return 0;
			}
		});
		
		for (int i=0;i<n;i++)
			rights.add(a.get(i));
		
		for (int i=0;i<n;i++)
			indexright[a.get(i).index]=i;

		BigInteger sumRight = BigInteger.ZERO;
		long mind=Long.MAX_VALUE;
		
		for (int i=0;i<n;i++) {
			sumRight=sumRight.add(BigInteger.valueOf(a.get(i).l));
			mind = min (mind, a.get(i).r-a.get(i).l);
		}
		
		Collections.sort(a, new Comparator<Segment>() {
			@Override
			public int compare(Segment o1, Segment o2) {
				if (o1.l<o2.l) return -1;
				if (o1.l>o2.l) return 1;
				return 0;
			}
		});
		
		int ll=0;
		long ans=0;
		int r=0;
		for (int i=0;i<lucky.size();i++) {
			while (ll<n && a.get(ll).l<=lucky.get(i)) {
				leftsum.inc(indexright[a.get(ll).index], a.get(ll).r);
				sumRight=sumRight.subtract(BigInteger.valueOf(a.get(ll).l));
				ll++;
			}
			if (r<i) r++;
			while(r<lucky.size()) {
				if (lucky.get(r)-lucky.get(i)>mind) break;
				long L=lucky.get(i);
				long R=lucky.get(r);
				int ls=-1; int rs=n;
				while (rs-ls>1) {
					int ms=(rs+ls)/2;
					if (rights.get(ms).r<=R) ls=ms; else rs=ms;
				}
				BigInteger sumOfLeft = BigInteger.ZERO;
				int count = 0;
				if (ls>=0) {
					sumOfLeft = leftsum.sum(ls);
					count = ls+1;
				}
				BigInteger sumLeft = BigInteger.valueOf(count).multiply(BigInteger.valueOf(R));
				sumOfLeft = sumLeft.subtract(sumOfLeft);
				long countOfRight = n-ll;
				BigInteger sumOfRight = BigInteger.valueOf(L).multiply(BigInteger.valueOf(countOfRight));
				sumOfRight = sumRight.subtract(sumOfRight);
				if (sumOfLeft.add(sumOfRight).compareTo(BigInteger.valueOf(k))<=0) {
					ans = max (ans, r-i+1);
					r++;
				}
				else break;
			}
		}
		
		out.println(ans);
		
	}
}
