import java.io.BufferedInputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

/**
 * Created by leen on 04/11/2017.
 */
public class _887D {

    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedInputStream(System.in, 1024 * 1024));
        int n = scan.nextInt(), a = scan.nextInt(), b = scan.nextInt(), c = scan.nextInt(), d = scan.nextInt();
        int start = scan.nextInt(), len = scan.nextInt();

        long[] e = new long[n], f = new long[n];
        int[] t = new int[n];

        for(int i = 0; i < n; i++) {
            t[i] = scan.nextInt();
            int type = scan.nextInt();
            long lastE = i > 0 ? e[i-1] : start;
            long lastF = i > 0 ? f[i-1] : start;

            if(type == 0) {
                e[i] = lastE - b;
                f[i] = lastF - d;
            }
            else {
                e[i] = lastE + a;
                f[i] = lastF + c;
            }
        }

        PriorityQueue<Long> minHeapF = new PriorityQueue<>();
        Map<Long,Integer> removed = new HashMap<>();

        for(int i = 0, j = 0; i < n; i++) {

            int talkShowTime = i == 0 ? 0 : t[i-1]+1;

            if(t[i] - talkShowTime >= len) { // No events during the duration of the influence of the talk show
                System.out.println(talkShowTime);
                return;
            }

            while(j < n && t[j]-talkShowTime<len) {
                minHeapF.add(f[j++]);
            }

            long lastE = i == 0 ? start : e[i-1];
            long lastF = i == 0 ? start : f[i-1];

            if(minHeapF.peek()-lastF+lastE >= 0) {
                System.out.println(talkShowTime);
                return;
            }

            if(e[i] < 0) {
                System.out.println(-1);
                return;
            }

            removed.compute(f[i], (k,v)->v==null?1:v+1);

            while(!minHeapF.isEmpty() && removed.getOrDefault(minHeapF.peek(), 0) > 0) {
                removed.compute(minHeapF.poll(), (k,v) -> v-1);
            }
        }

        System.out.println(t[n-1]+1);

    }
}


import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by leen on 04/11/2017.
 */
public class _887D {

    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedInputStream(System.in, 1024*1024));
        int n = scan.nextInt(), a = scan.nextInt(), b = scan.nextInt(), c = scan.nextInt(), d = scan.nextInt();
        int start = scan.nextInt(), len = scan.nextInt();

        int[] t = new int[n]; // time
        long[] e = new long[n]; // rating using a and b
        long[] f = new long[n]; // rating using c and d

        for(int i = 0; i < n; i++) {
            t[i] = scan.nextInt();
            int type = scan.nextInt();
            long lastE = i > 0 ? e[i-1] : start;
            long lastF = i > 0 ? f[i-1] : start;
            if(type == 0) {
                e[i] = lastE - b;
                f[i] = lastF - d;
            }
            else {
                e[i] = lastE + a;
                f[i] = lastF + c;
            }
        }

        int range = 1;
        while(range < n)
            range <<= 1;

        long[] tree = new long[range*2-1];
        Arrays.fill(tree, Long.MAX_VALUE);
        System.arraycopy(f, 0, tree, range-1, n);

        for(int i = range-2; i >= 0; i--) {
            tree[i] = Math.min(tree[i*2+1], tree[i*2+2]);
        }

        for(int i = 0; i < n; i++) {
            long currentE = i > 0 ? e[i-1] : start;
            long currentF = i > 0 ? f[i-1] : start;

            long minInRange = queryMinInRange(tree, 0, i, i+len-1, 0, n-1);

            if(minInRange - currentF + currentE >= 0) {
                System.out.println(t[i]);
                return;
            }
            else if(currentE < 0) {
                System.out.println(-1);
                return;
            }
        }

        if(e[n-1] >= 0)
            System.out.println(t[n-1]+1);
        else
            System.out.println(-1);

    }

    private static long queryMinInRange(long[] tree, int node, int left, int right, int nodeLeft, int nodeRight) {
        if(right < nodeLeft || left > nodeRight)
            return Long.MAX_VALUE;

        if(left <= nodeLeft && right >= nodeRight)
            return tree[node];

        int halfRangeLen = (nodeRight-nodeLeft+1)/2;
        long leftMin = queryMinInRange(tree, node*2+1, left, right, nodeLeft, nodeLeft+halfRangeLen-1);
        long rightMin = queryMinInRange(tree, node*2+2, left, right, nodeLeft+halfRangeLen, nodeRight);
        return Math.min(leftMin, rightMin);
    }

}


import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by leen on 04/11/2017.
 */
public class _887D {

    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedInputStream(System.in, 1024*1024));
        int n = scan.nextInt(), a = scan.nextInt(), b = scan.nextInt(), c = scan.nextInt(), d = scan.nextInt();
        int start = scan.nextInt(), len = scan.nextInt();

        int[] t = new int[n]; // time
        long[] e = new long[n]; // rating using a and b
        long[] f = new long[n]; // rating using c and d

        for(int i = 0; i < n; i++) {
            t[i] = scan.nextInt();
            int type = scan.nextInt();
            long lastE = i > 0 ? e[i-1] : start;
            long lastF = i > 0 ? f[i-1] : start;
            if(type == 0) {
                e[i] = lastE - b;
                f[i] = lastF - d;
            }
            else {
                e[i] = lastE + a;
                f[i] = lastF + c;
            }
        }

        int range = 1;
        while(range < n)
            range <<= 1;

        long[] tree = new long[range*2-1];
        Arrays.fill(tree, Long.MAX_VALUE);
        System.arraycopy(f, 0, tree, range-1, n);

        for(int i = range-2; i >= 0; i--) {
            tree[i] = Math.min(tree[i*2+1], tree[i*2+2]);
        }

        for(int i = 0; i < n; i++) {
            long currentE = i > 0 ? e[i-1] : start;

            if(currentE < 0) {
                System.out.println(-1);
                return;
            }

            long currentF = i > 0 ? f[i-1] : start;

            long minInRange = queryMinInRange(tree, 0, i, i+len-1, 0, range-1);

            if(minInRange - currentF + currentE >= 0) {
                System.out.println(t[i]);
                return;
            }
        }

        if(e[n-1] >= 0)
            System.out.println(t[n-1]+1);
        else
            System.out.println(-1);

    }

    private static long queryMinInRange(long[] tree, int node, int left, int right, int nodeLeft, int nodeRight) {
        if(right < nodeLeft || left > nodeRight)
            return Long.MAX_VALUE;

        if(left <= nodeLeft && right >= nodeRight)
            return tree[node];

        int halfRangeLen = (nodeRight-nodeLeft+1)/2;
        long leftMin = queryMinInRange(tree, node*2+1, left, right, nodeLeft, nodeLeft+halfRangeLen-1);
        long rightMin = queryMinInRange(tree, node*2+2, left, right, nodeLeft+halfRangeLen, nodeRight);
        return Math.min(leftMin, rightMin);
    }

}


import java.io.BufferedInputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

/**
 * Created by leen on 04/11/2017.
 */
public class _887D {

    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedInputStream(System.in, 1024 * 1024));
        int n = scan.nextInt(), a = scan.nextInt(), b = scan.nextInt(), c = scan.nextInt(), d = scan.nextInt();
        int start = scan.nextInt(), len = scan.nextInt();

        long[] e = new long[n+1], f = new long[n+1];
        int[] t = new int[n+1];

        t[0] = -1;
        e[0] = f[0] = start;

        for(int i = 1; i <= n; i++) {
            t[i] = scan.nextInt();
            int type = scan.nextInt();

            if(type == 0) {
                e[i] = e[i-1] - b;
                f[i] = f[i-1] - d;
            }
            else {
                e[i] = e[i-1] + a;
                f[i] = f[i-1] + c;
            }
        }

        PriorityQueue<Long> minHeapF = new PriorityQueue<>();
        Map<Long,Integer> removed = new HashMap<>();

        for(int i = 1, j = 1; i <= n; i++) {

            int talkShowTime = t[i-1]+1;

            if(t[i] - talkShowTime >= len) { // No events during the duration of the influence of the talk show
                System.out.println(talkShowTime);
                return;
            }

            while(j <= n && t[j]-talkShowTime<len) {
                minHeapF.add(f[j++]);
            }

            if(minHeapF.peek()-f[i-1]+e[i-1] >= 0) {
                System.out.println(talkShowTime);
                return;
            }

            if(e[i] < 0) {
                System.out.println(-1);
                return;
            }

            removed.compute(f[i], (k,v)->v==null?1:v+1);

            while(!minHeapF.isEmpty() && removed.getOrDefault(minHeapF.peek(), 0) > 0) {
                removed.compute(minHeapF.poll(), (k,v) -> v-1);
            }
        }

        System.out.println(t[n]+1);

    }
}


import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by leen on 04/11/2017.
 */
public class _887D {

    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedInputStream(System.in, 1024*1024));
        int n = scan.nextInt(), a = scan.nextInt(), b = scan.nextInt(), c = scan.nextInt(), d = scan.nextInt();
        int start = scan.nextInt(), len = scan.nextInt();

        int[] t = new int[n]; // time
        long[] e = new long[n]; // rating using a and b
        long[] f = new long[n]; // rating using c and d

        for(int i = 0; i < n; i++) {
            t[i] = scan.nextInt();
            int type = scan.nextInt();
            long lastE = i > 0 ? e[i-1] : start;
            long lastF = i > 0 ? f[i-1] : start;
            if(type == 0) {
                e[i] = lastE - b;
                f[i] = lastF - d;
            }
            else {
                e[i] = lastE + a;
                f[i] = lastF + c;
            }
        }

        int range = 1;
        while(range < n)
            range <<= 1;

        long[] tree = new long[range*2-1];
        Arrays.fill(tree, Long.MAX_VALUE);
        System.arraycopy(f, 0, tree, range-1, n);

        for(int i = range-2; i >= 0; i--) {
            tree[i] = Math.min(tree[i*2+1], tree[i*2+2]);
        }

        for(int i = 0; i < n; i++) {
            long currentE = i > 0 ? e[i-1] : start;
            long currentF = i > 0 ? f[i-1] : start;

            long minInRange = queryMinInRange(tree, 0, i, i+len-1, 0, range-1);

            if(minInRange - currentF + currentE >= 0) {
                System.out.println(t[i]);
                return;
            }
            else if(currentE < 0) {
                System.out.println(-1);
                return;
            }
        }

        if(e[n-1] >= 0)
            System.out.println(t[n-1]+1);
        else
            System.out.println(-1);

    }

    private static long queryMinInRange(long[] tree, int node, int left, int right, int nodeLeft, int nodeRight) {
        if(right < nodeLeft || left > nodeRight)
            return Long.MAX_VALUE;

        if(left <= nodeLeft && right >= nodeRight)
            return tree[node];

        int halfRangeLen = (nodeRight-nodeLeft+1)/2;
        long leftMin = queryMinInRange(tree, node*2+1, left, right, nodeLeft, nodeLeft+halfRangeLen-1);
        long rightMin = queryMinInRange(tree, node*2+2, left, right, nodeLeft+halfRangeLen, nodeRight);
        return Math.min(leftMin, rightMin);
    }

}


import java.io.*;
import java.util.*;

public class Template implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            String filename = "";
            if (!filename.isEmpty()) {
                in = new BufferedReader(new FileReader(filename + ".in"));
                out = new PrintWriter(filename + ".out");
            } else {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            }
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    int[] readIntArray(int size) throws IOException {
        int[] res = new int[size];
        for (int i = 0; i < size; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    <T> List<T>[] createGraphList(int size) {
        List<T>[] list = new List[size];
        for (int i = 0; i < size; i++) {
            list[i] = new ArrayList<>();
        }
        return list;
    }

    public static void main(String[] args) {
        new Template().run();
//        new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory() {
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
                + " KB");
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            if (System.getProperty("ONLINE_JUDGE") == null) {
                time();
                memory();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    class SegmentTree {
        long[] min;
        long[] sum;

        SegmentTree(int[] events, int a, int b) {
            min = new long[events.length * 4];
            sum = new long[events.length * 4];
            n = events.length;
            build(1, 0, n - 1, a, b, events);
        }

        void build(int v, int tl, int tr, int a, int b, int[] events) {
            if (tl == tr) {
                min[v] = Math.min(min[v], events[tl] == 1 ? a : -b);
                sum[v] = events[tl] == 1 ? a : -b;
                return;
            }
            int mid = (tl + tr) >> 1;
            build(v * 2, tl, mid, a, b, events);
            build(v * 2 + 1, mid + 1, tr, a, b, events);
            min[v] = Math.min(min[v * 2], sum[v * 2] + min[v * 2 + 1]);
            sum[v] = sum[v * 2] + sum[v * 2 + 1];
        }

        long[] get(int v, int tl, int tr, int l, int r) {
            if (tl == l && tr == r) {
                return new long[]{min[v], sum[v]};
            }
            int mid = (tl + tr) >> 1;
            if (r <= mid) {
                return get(v * 2, tl, mid, l, r);
            } else if (l > mid) {
                return get(v * 2 + 1, mid + 1, tr, l, r);
            } else {
                long[] f = get(v * 2, tl, mid, l, mid);
                long[] s = get(v * 2 + 1, mid + 1, tr, mid + 1, r);
                return merge(f, s);
            }
        }

        long[] get(int l, int r) {
            if (l > r) return new long[]{0, 0};
            return get(1, 0, n - 1, l, r);
        }

        int n;
    }

    long[] merge(long[] f, long[] s) {
        long[] res = new long[2];
        res[0] = Math.min(f[0], f[1] + s[0]);
        res[1] = f[1] + s[1];
        return res;
    }

    void solve() throws IOException {
        int n = readInt();
        int a = readInt(), b = readInt(), c = readInt(), d = readInt();
        int start = readInt();
        int len = readInt();
        List<Integer> timestamps = new ArrayList<>();
        timestamps.add(0);
        int[] t = new int[n];
        int[] type = new int[n];
        for (int i = 0; i < n; i++) {
            t[i] = readInt();
            type[i] = readInt();
            timestamps.add(t[i]);
            timestamps.add(t[i] + 1);
            timestamps.add(t[i] - len);
            timestamps.add(t[i] - len + 1);
        }

        SegmentTree abst = new SegmentTree(type, a, b);
        SegmentTree cdst = new SegmentTree(type, c, d);

        Collections.sort(timestamps);
        int l = -1;
        for (int x : timestamps) {
            if (l == x) continue;
            l = x;
            if (ok(x, abst, cdst, t, start, len)) {
                out.println(x);
                return;
            }
        }
        out.println(-1);
    }

    boolean ok(int time, SegmentTree abst, SegmentTree cdst, int[] times, int start, int len) {
        if (time < 0) return false;
        int middleL = findGE(times, time);
        int middleR = findLE(times, time + len - 1);
        long[] x = new long[]{0, start};
        x = merge(x, abst.get(0, middleL - 1));
        x = merge(x, cdst.get(middleL, middleR));
//        x = merge(x, abst.get(middleR + 1, times.length - 1));
        return x[0] == 0;
    }

    int findGE(int[] times, int time) {
        int bs = Arrays.binarySearch(times, time);
        if (bs >= 0) return bs;
        return -bs - 1;
    }

    int findLE(int[] times, int time) {
        int bs = Arrays.binarySearch(times, time);
        if (bs >= 0) return bs;
        return -bs - 2;
    }

}


import java.io.*;
import java.util.*;
import java.math.*;
import java.util.concurrent.*;

public final class ratings_and_reality
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static long[] tree,arr;

	static void build(int node,int s,int e)
	{
		if(s>e)
		{
			return;
		}

		if(s==e)
		{
			tree[node]=arr[s];
		}

		else
		{
			int mid=(s+e)>>1;

			build(node<<1,s,mid);build(node<<1|1,mid+1,e);

			tree[node]=Math.min(tree[node<<1],tree[node<<1|1]);
		}
	}

	static long query(int node,int s,int e,int l,int r)
	{
		if(s>e || l>e || r<s)
		{
			return Long.MAX_VALUE;
		}

		if(l<=s && r>=e)
		{
			return tree[node];
		}

		else
		{
			int mid=(s+e)>>1;

			return Math.min(query(node<<1,s,mid,l,r),query(node<<1|1,mid+1,e,l,r));
		}
	}

    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt();long a=sc.nextLong(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();

		long add1=sc.nextLong();int len=sc.nextInt();

		int[] t=new int[n+1];long[] cnt1=new long[n+1],cnt2=new long[n+1];

		int val1=0,val2=0;

		for(int i=1;i<=n;i++)
		{
			t[i]=sc.nextInt();

			int idx=sc.nextInt();

			if(idx==0)
			{
				val1++;
			}

			else
			{
				val2++;
			}

			cnt1[i]=val1;cnt2[i]=val2;
		}

		arr=new long[n+1];

		for(int i=1;i<=n;i++)
		{
			arr[i]=(-d*cnt1[i])+(c*cnt2[i]);
		}

		tree=new long[4*(n+1)];build(1,1,n);long ans=Integer.MAX_VALUE;

		for(int i=0;i<=n;i++)
		{
			int start=t[i],end=t[i]+len-1;

			int low=i,high=n;

			while(low<high)
			{
				int mid=(low+high+1)>>1;

				if(t[mid]<=end)
				{
					low=mid;
				}

				else
				{
					high=mid-1;
				}
			}

			long min=query(1,1,n,i,low)+add1;

			long prev1=(i==0)?0:cnt2[i-1],prev2=(i==0?0:cnt1[i-1]);

			long add=(-1*prev1*c)+(prev2*d);

			min+=add;

			long sub=(prev1*a)+(prev2*b*-1);

			min+=sub;

			if(min>=0)
			{
				ans=Math.min(ans,start);
			}

			long now=(cnt2[i]*a)-(cnt1[i]*b)+add1;

			if(now<0)
			{
				break;
			}
		}

		for(int i=0;i<=n;i++)
		{
			long now=(cnt2[i]*a)-(cnt1[i]*b)+add1;

			if(now<0)
			{
				break;
			}

			int start=t[i]+1,end=t[i]+len;

			if(i+1<=n && t[i+1]<=end)
			{
				int low=i+1,high=n;

				while(low<high)
				{
					int mid=(low+high+1)>>1;

					if(t[mid]<=end)
					{
						low=mid;
					}

					else
					{
						high=mid-1;
					}
				}

				long min=query(1,1,n,i+1,low)+add1;

				long add=(-1*cnt2[i]*c)+(cnt1[i]*d);

				min+=add;

				long sub=(cnt2[i]*a)+(cnt1[i]*b*-1);

				min+=sub;

				if(min>=0)
				{
					ans=Math.min(ans,start);
				}
			}

			else
			{
				ans=Math.min(ans,t[i]+1);
			}
		}

		out.println(ans<Integer.MAX_VALUE?ans:-1);out.close();
    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

	public String next() throws Exception {
		return nextToken().toString();
	}

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

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

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


import java.io.*;
import java.util.*;
import java.math.*;
import java.util.concurrent.*;

public final class ratings_and_reality
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static long[] tree,arr;

	static void build(int node,int s,int e)
	{
		if(s>e)
		{
			return;
		}

		if(s==e)
		{
			tree[node]=arr[s];
		}

		else
		{
			int mid=(s+e)>>1;

			build(node<<1,s,mid);build(node<<1|1,mid+1,e);

			tree[node]=Math.min(tree[node<<1],tree[node<<1|1]);
		}
	}

	static long query(int node,int s,int e,int l,int r)
	{
		if(s>e || l>e || r<s)
		{
			return Long.MAX_VALUE;
		}

		if(l<=s && r>=e)
		{
			return tree[node];
		}

		else
		{
			int mid=(s+e)>>1;

			return Math.min(query(node<<1,s,mid,l,r),query(node<<1|1,mid+1,e,l,r));
		}
	}

    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt();long a=sc.nextLong(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();

		long add1=sc.nextLong();int len=sc.nextInt();

		int[] t=new int[n+1];long[] cnt1=new long[n+1],cnt2=new long[n+1];

		int val1=0,val2=0;

		for(int i=1;i<=n;i++)
		{
			t[i]=sc.nextInt();

			int idx=sc.nextInt();

			if(idx==0)
			{
				val1++;
			}

			else
			{
				val2++;
			}

			cnt1[i]=val1;cnt2[i]=val2;
		}

		arr=new long[n+1];

		for(int i=1;i<=n;i++)
		{
			arr[i]=(-d*cnt1[i])+(c*cnt2[i]);
		}

		tree=new long[4*(n+1)];build(1,1,n);long ans=Integer.MAX_VALUE;

		for(int i=1;i<=n;i++)
		{
			int start=t[i],end=t[i]+len-1;

			int low=i,high=n;

			while(low<high)
			{
				int mid=(low+high+1)>>1;

				if(t[mid]<=end)
				{
					low=mid;
				}

				else
				{
					high=mid-1;
				}
			}

			long min=query(1,1,n,i,low)+add1;

			long add=(-1*cnt2[i-1]*c)+(cnt1[i-1]*d);

			min+=add;

			long sub=(cnt2[i-1]*a)+(cnt1[i-1]*b*-1);

			min+=sub;

			if(min>=0)
			{
				ans=Math.min(ans,start);
			}

			long now=(cnt2[i]*a)-(cnt1[i]*b)+add1;

			if(now<0)
			{
				break;
			}
		}

		for(int i=0;i<=n;i++)
		{
			long now=(cnt2[i]*a)-(cnt1[i]*b)+add1;

			if(now<0)
			{
				break;
			}

			int start=t[i]+1,end=t[i]+len;

			if(i+1<=n && t[i+1]<=end)
			{
				int low=i+1,high=n;

				while(low<high)
				{
					int mid=(low+high+1)>>1;

					if(t[mid]<=end)
					{
						low=mid;
					}

					else
					{
						high=mid-1;
					}
				}

				long min=query(1,1,n,i+1,low)+add1;

				long add=(-1*cnt2[i]*c)+(cnt1[i]*d);

				min+=add;

				long sub=(cnt2[i]*a)+(cnt1[i]*b*-1);

				min+=sub;

				if(min>=0)
				{
					ans=Math.min(ans,start);
				}
			}

			else
			{
				ans=Math.min(ans,t[i]+1);
			}
		}

		out.println(ans<Integer.MAX_VALUE?ans:-1);out.close();
    }

	private static class Pair
	{
		int l,r;

		public Pair(int l,int r)
		{
			this.l=l;this.r=r;
		}
	}
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

	public String next() throws Exception {
		return nextToken().toString();
	}

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

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

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


import java.io.*;
import java.util.*;
import java.math.*;
import java.util.concurrent.*;

public final class ratings_and_reality
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static long[] tree,arr;

	static void build(int node,int s,int e)
	{
		if(s>e)
		{
			return;
		}

		if(s==e)
		{
			tree[node]=arr[s];
		}

		else
		{
			int mid=(s+e)>>1;

			build(node<<1,s,mid);build(node<<1|1,mid+1,e);

			tree[node]=Math.min(tree[node<<1],tree[node<<1|1]);
		}
	}

	static long query(int node,int s,int e,int l,int r)
	{
		if(s>e || l>e || r<s)
		{
			return Long.MAX_VALUE;
		}

		if(l<=s && r>=e)
		{
			return tree[node];
		}

		else
		{
			int mid=(s+e)>>1;

			return Math.min(query(node<<1,s,mid,l,r),query(node<<1|1,mid+1,e,l,r));
		}
	}

    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt();long a=sc.nextLong(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();

		long add1=sc.nextLong();int len=sc.nextInt();

		int[] t=new int[n+1];long[] cnt1=new long[n+1],cnt2=new long[n+1];

		int val1=0,val2=0;

		for(int i=1;i<=n;i++)
		{
			t[i]=sc.nextInt();

			int idx=sc.nextInt();

			if(idx==0)
			{
				val1++;
			}

			else
			{
				val2++;
			}

			cnt1[i]=val1;cnt2[i]=val2;
		}

		arr=new long[n+1];

		for(int i=1;i<=n;i++)
		{
			arr[i]=(-d*cnt1[i])+(c*cnt2[i]);
		}

		tree=new long[4*(n+1)];build(1,1,n);long ans=Integer.MAX_VALUE;

		for(int i=1;i<=n;i++)
		{
			int start=t[i],end=t[i]+len-1;

			int low=i,high=n;

			while(low<high)
			{
				int mid=(low+high+1)>>1;

				if(t[mid]<=end)
				{
					low=mid;
				}

				else
				{
					high=mid-1;
				}
			}

			long min=query(1,1,n,i,low)+add1;

			long add=(-1*cnt2[i-1]*c)+(cnt1[i-1]*d);

			min+=add;

			long sub=(cnt2[i-1]*a)+(cnt1[i-1]*b*-1);

			min+=sub;

			if(min>=0)
			{
				ans=Math.min(ans,start);
			}

			long now=(cnt2[i]*a)-(cnt1[i]*b)+add1;

			if(now<0)
			{
				break;
			}
		}

		for(int i=1;i<=n;i++)
		{
			long now=(cnt2[i]*a)-(cnt1[i]*b)+add1;

			if(now<0)
			{
				break;
			}

			int start=t[i]+1,end=t[i]+len;

			if(i+1<=n && t[i+1]<=end)
			{
				int low=i+1,high=n;

				while(low<high)
				{
					int mid=(low+high+1)>>1;

					if(t[mid]<=end)
					{
						low=mid;
					}

					else
					{
						high=mid-1;
					}
				}

				long min=query(1,1,n,i+1,low)+add1;

				long add=(-1*cnt2[i]*c)+(cnt1[i]*d);

				min+=add;

				long sub=(cnt2[i]*a)+(cnt1[i]*b*-1);

				min+=sub;

				if(min>=0)
				{
					ans=Math.min(ans,start);
				}
			}

			else
			{
				ans=Math.min(ans,t[i]+1);
			}
		}

		out.println(ans<Integer.MAX_VALUE?ans:-1);out.close();
    }

	private static class Pair
	{
		int l,r;

		public Pair(int l,int r)
		{
			this.l=l;this.r=r;
		}
	}
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

	public String next() throws Exception {
		return nextToken().toString();
	}

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

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

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


import java.io.*;
import java.util.*;
import java.math.*;
import java.util.concurrent.*;

public final class ratings_and_reality
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static long[] tree,arr;

	static void build(int node,int s,int e)
	{
		if(s>e)
		{
			return;
		}

		if(s==e)
		{
			tree[node]=arr[s];
		}

		else
		{
			int mid=(s+e)>>1;

			build(node<<1,s,mid);build(node<<1|1,mid+1,e);

			tree[node]=Math.min(tree[node<<1],tree[node<<1|1]);
		}
	}

	static long query(int node,int s,int e,int l,int r)
	{
		if(s>e || l>e || r<s)
		{
			return Long.MAX_VALUE;
		}

		if(l<=s && r>=e)
		{
			return tree[node];
		}

		else
		{
			int mid=(s+e)>>1;

			return Math.min(query(node<<1,s,mid,l,r),query(node<<1|1,mid+1,e,l,r));
		}
	}

    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt();long a=sc.nextLong(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();

		long add1=sc.nextLong();int len=sc.nextInt();

		int[] t=new int[n+1];long[] cnt1=new long[n+1],cnt2=new long[n+1];

		int val1=0,val2=0;

		for(int i=1;i<=n;i++)
		{
			t[i]=sc.nextInt();

			int idx=sc.nextInt();

			if(idx==0)
			{
				val1++;
			}

			else
			{
				val2++;
			}

			cnt1[i]=val1;cnt2[i]=val2;
		}

		arr=new long[n+1];

		for(int i=1;i<=n;i++)
		{
			arr[i]=(-d*cnt1[i])+(c*cnt2[i]);
		}

		tree=new long[4*(n+1)];build(1,1,n);long ans=Integer.MAX_VALUE;

		for(int i=1;i<=n;i++)
		{
			int start=t[i],end=t[i]+len-1;

			int low=i,high=n;

			while(low<high)
			{
				int mid=(low+high+1)>>1;

				if(t[mid]<=end)
				{
					low=mid;
				}

				else
				{
					high=mid-1;
				}
			}

			long min=query(1,1,n,i,low)+add1;

			long add=(-1*cnt2[i-1]*c)+(cnt1[i-1]*d);

			min+=add;

			long sub=(cnt2[i-1]*a)+(cnt1[i-1]*b*-1);

			min+=sub;

			if(min>=0)
			{
				ans=Math.min(ans,start);
			}

			long now=(cnt2[i]*a)-(cnt1[i]*b)+add1;

			if(now<0)
			{
				break;
			}
		}

		for(int i=0;i<=n;i++)
		{
			long now=(cnt2[i]*a)-(cnt1[i]*b)+add1;

			if(now<0)
			{
				break;
			}

			int start=t[i]+1,end=t[i]+len;

			if(i+1<=n && t[i+1]<=end)
			{
				int low=i+1,high=n;

				while(low<high)
				{
					int mid=(low+high+1)>>1;

					if(t[mid]<=end)
					{
						low=mid;
					}

					else
					{
						high=mid-1;
					}
				}

				long min=query(1,1,n,i+1,low)+add1;

				long add=(-1*cnt2[i]*c)+(cnt1[i]*d);

				min+=add;

				long sub=(cnt2[i]*a)+(cnt1[i]*b*-1);

				min+=sub;

				if(min>=0)
				{
					ans=Math.min(ans,start);
				}
			}

			else
			{
				ans=Math.min(ans,t[i]+1);
			}
		}

		out.println(ans<Integer.MAX_VALUE?ans:-1);out.close();
    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

	public String next() throws Exception {
		return nextToken().toString();
	}

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

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

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


import java.io.*;
import java.util.*;
import java.math.*;
import java.util.concurrent.*;

public final class ratings_and_reality
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static long[] tree,arr;

	static void build(int node,int s,int e)
	{
		if(s>e)
		{
			return;
		}

		if(s==e)
		{
			tree[node]=arr[s];
		}

		else
		{
			int mid=(s+e)>>1;

			build(node<<1,s,mid);build(node<<1|1,mid+1,e);

			tree[node]=Math.min(tree[node<<1],tree[node<<1|1]);
		}
	}

	static long query(int node,int s,int e,int l,int r)
	{
		if(s>e || l>e || r<s)
		{
			return Long.MAX_VALUE;
		}

		if(l<=s && r>=e)
		{
			return tree[node];
		}

		else
		{
			int mid=(s+e)>>1;

			return Math.min(query(node<<1,s,mid,l,r),query(node<<1|1,mid+1,e,l,r));
		}
	}

    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt();long a=sc.nextLong(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();

		long add1=sc.nextLong();int len=sc.nextInt();

		int[] t=new int[n+1];long[] cnt1=new long[n+1],cnt2=new long[n+1];

		int val1=0,val2=0;

		for(int i=1;i<=n;i++)
		{
			t[i]=sc.nextInt();

			int idx=sc.nextInt();

			if(idx==0)
			{
				val1++;
			}

			else
			{
				val2++;
			}

			cnt1[i]=val1;cnt2[i]=val2;
		}

		arr=new long[n+1];

		for(int i=1;i<=n;i++)
		{
			arr[i]=(-d*cnt1[i])+(c*cnt2[i]);
		}

		tree=new long[4*(n+1)];build(1,1,n);long ans=Integer.MAX_VALUE;

		for(int i=0;i<=n;i++)
		{
			int start=t[i],end=t[i]+len-1;

			int low=i,high=n;

			while(low<high)
			{
				int mid=(low+high+1)>>1;

				if(t[mid]<=end)
				{
					low=mid;
				}

				else
				{
					high=mid-1;
				}
			}

			long min=query(1,1,n,i,low)+add1;

			long add=(-1*cnt2[i-1]*c)+(cnt1[i-1]*d);

			min+=add;

			long sub=(cnt2[i-1]*a)+(cnt1[i-1]*b*-1);

			min+=sub;

			if(min>=0)
			{
				ans=Math.min(ans,start);
			}

			long now=(cnt2[i]*a)-(cnt1[i]*b)+add1;

			if(now<0)
			{
				break;
			}
		}

		for(int i=0;i<=n;i++)
		{
			long now=(cnt2[i]*a)-(cnt1[i]*b)+add1;

			if(now<0)
			{
				break;
			}

			int start=t[i]+1,end=t[i]+len;

			if(i+1<=n && t[i+1]<=end)
			{
				int low=i+1,high=n;

				while(low<high)
				{
					int mid=(low+high+1)>>1;

					if(t[mid]<=end)
					{
						low=mid;
					}

					else
					{
						high=mid-1;
					}
				}

				long min=query(1,1,n,i+1,low)+add1;

				long add=(-1*cnt2[i]*c)+(cnt1[i]*d);

				min+=add;

				long sub=(cnt2[i]*a)+(cnt1[i]*b*-1);

				min+=sub;

				if(min>=0)
				{
					ans=Math.min(ans,start);
				}
			}

			else
			{
				ans=Math.min(ans,t[i]+1);
			}
		}

		out.println(ans<Integer.MAX_VALUE?ans:-1);out.close();
    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

	public String next() throws Exception {
		return nextToken().toString();
	}

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

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

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


import java.io.*;
import java.util.*;
import java.math.*;
import java.util.concurrent.*;

public final class ratings_and_reality
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	static long[] tree,arr;

	static void build(int node,int s,int e)
	{
		if(s>e)
		{
			return;
		}

		if(s==e)
		{
			tree[node]=arr[s];
		}

		else
		{
			int mid=(s+e)>>1;

			build(node<<1,s,mid);build(node<<1|1,mid+1,e);

			tree[node]=Math.min(tree[node<<1],tree[node<<1|1]);
		}
	}

	static long query(int node,int s,int e,int l,int r)
	{
		if(s>e || l>e || r<s)
		{
			return Long.MAX_VALUE;
		}

		if(l<=s && r>=e)
		{
			return tree[node];
		}

		else
		{
			int mid=(s+e)>>1;

			return Math.min(query(node<<1,s,mid,l,r),query(node<<1|1,mid+1,e,l,r));
		}
	}

    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt();long a=sc.nextLong(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();

		long add1=sc.nextLong();int len=sc.nextInt();

		int[] t=new int[n+1];long[] cnt1=new long[n+1],cnt2=new long[n+1];

		int val1=0,val2=0;

		for(int i=1;i<=n;i++)
		{
			t[i]=sc.nextInt();

			int idx=sc.nextInt();

			if(idx==0)
			{
				val1++;
			}

			else
			{
				val2++;
			}

			cnt1[i]=val1;cnt2[i]=val2;
		}

		arr=new long[n+1];

		for(int i=1;i<=n;i++)
		{
			arr[i]=(-d*cnt1[i])+(c*cnt2[i]);
		}

		tree=new long[4*(n+1)];build(1,1,n);long ans=Integer.MAX_VALUE;

		for(int i=1;i<=n;i++)
		{
			int start=t[i],end=t[i]+len-1;

			int low=i,high=n;

			while(low<high)
			{
				int mid=(low+high+1)>>1;

				if(t[mid]<=end)
				{
					low=mid;
				}

				else
				{
					high=mid-1;
				}
			}

			long min=query(1,1,n,i,low)+add1;

			long add=(-1*cnt2[i-1]*c)+(cnt1[i-1]*d);

			min+=add;

			long sub=(cnt2[i-1]*a)+(cnt1[i-1]*b*-1);

			min+=sub;

			if(min>=0)
			{
				ans=Math.min(ans,start);
			}

			long now=(cnt2[i]*a)-(cnt1[i]*b);

			if(now<0)
			{
				break;
			}
		}

		for(int i=1;i<=n;i++)
		{
			long now=(cnt2[i]*a)-(cnt1[i]*b);

			if(now<0)
			{
				break;
			}

			int start=t[i]+1,end=t[i]+len;

			if(i+1<=n && t[i+1]<=end)
			{
				int low=i+1,high=n;

				while(low<high)
				{
					int mid=(low+high+1)>>1;

					if(t[mid]<=end)
					{
						low=mid;
					}

					else
					{
						high=mid-1;
					}
				}

				long min=query(1,1,n,i+1,low)+add1;

				long add=(-1*cnt2[i]*c)+(cnt1[i]*d);

				min+=add;

				long sub=(cnt2[i]*a)+(cnt1[i]*b*-1);

				min+=sub;

				if(min>=0)
				{
					ans=Math.min(ans,start);
				}
			}

			else
			{
				ans=Math.min(ans,t[i]+1);
			}
		}

		out.println(ans<Integer.MAX_VALUE?ans:-1);out.close();
    }

	private static class Pair
	{
		int l,r;

		public Pair(int l,int r)
		{
			this.l=l;this.r=r;
		}
	}
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

	public String next() throws Exception {
		return nextToken().toString();
	}

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

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

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


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MAXN = 300010;
const int LOGN = 20;
int _w;

int n, a, b, c, d, start, len;
int t[MAXN], q[MAXN];

struct Info {
	ll rt, dt;
	Info() {}
	Info( ll rt, ll dt ):
		rt(rt), dt(dt) {}
	void init( ll d ) {
		dt = d;
		rt = max(0LL, -d);
	}
	void merge( Info a, Info b ) {
		dt = a.dt + b.dt;
		rt = max(a.rt, b.rt - a.dt);
	}
};

Info f[MAXN][LOGN], g[MAXN][LOGN];
int ev[MAXN*2], evsz;
void prelude() {
	for( int i = 1; i <= n; ++i ) {
		g[i][0].init( q[i] ? c : -d );
		f[i][0].init( q[i] ? a : -b );
	}
	for( int k = 0; k < LOGN; ++k )
		for( int i = 1; i+(1<<(k+1))-1 <= n; ++i ) {
			g[i][k+1].merge( g[i][k], g[i+(1<<k)][k] );
			f[i][k+1].merge( f[i][k], f[i+(1<<k)][k] );
		}
	for( int i = 1; i <= n; ++i ) {
		ev[evsz++] = t[i]+1;
		ev[evsz++] = max(0, t[i]-len+1);
	}
	ev[evsz++] = 0;
	sort(ev, ev+evsz);
	evsz = int(unique(ev, ev+evsz) - ev);
}

void cover( int tm, int &L, int &R ) {
	L = tm, R = tm+len-1;
	L = int(lower_bound(t+1, t+n+1, L) - t);
	R = int(upper_bound(t+1, t+n+1, R) - t) - 1;
}

Info query( Info f[MAXN][LOGN], int L, int R ) {
	if( L > R ) return Info(0, 0);
	Info ans(0, 0);
	for( int k = LOGN-1; k >= 0; --k ) {
		if( L+(1<<k)-1 > R ) continue;
		ans.merge( ans, f[L][k] );
		L += 1<<k;
	}
	return ans;
}

int main() {
	_w = scanf( "%d%d%d%d%d%d%d", &n, &a, &b, &c, &d, &start, &len );
	for( int i = 1; i <= n; ++i )
		_w = scanf( "%d%d", t+i, q+i );
	prelude();
	for( int i = 0; i < evsz; ++i ) {
		int L, R;
		cover(ev[i], L, R);
		Info left = query(f, 1, L-1);
		Info mid = query(g, L, R);
		ll rating = start;
		if( rating < left.rt ) continue;
		else rating += left.dt;
		if( rating >= mid.rt )
			return printf( "%d\n", ev[i] ), 0;
	}
	puts("-1");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MAXN = 300010;
const int LOGN = 20;
int _w;

int n, a, b, c, d, start, len;
int t[MAXN], q[MAXN];

struct Info {
	ll rt, dt;
	Info() {}
	Info( ll rt, ll dt ):
		rt(rt), dt(dt) {}
	void init( ll d ) {
		dt = d;
		rt = max(0LL, -d);
	}
	void merge( Info a, Info b ) {
		dt = a.dt + b.dt;
		rt = max(a.rt, b.rt - a.dt);
	}
	bool check( ll rating ) const {
		return rating >= rt;
	}
	ll run( ll rating ) const {
		return rating + dt;
	}
};

Info f[MAXN][LOGN], g[MAXN][LOGN];
int ev[MAXN*2], evsz;
void prelude() {
	for( int i = 1; i <= n; ++i ) {
		g[i][0].init( q[i] ? c : -d );
		f[i][0].init( q[i] ? a : -b );
	}
	for( int k = 0; k < LOGN; ++k )
		for( int i = 1; i+(1<<(k+1))-1 <= n; ++i ) {
			g[i][k+1].merge( g[i][k], g[i+(1<<k)][k] );
			f[i][k+1].merge( f[i][k], f[i+(1<<k)][k] );
		}
	for( int i = 1; i <= n; ++i ) {
		ev[evsz++] = t[i]+1;
		ev[evsz++] = max(0, t[i]-len+1);
	}
	ev[evsz++] = 0;
	sort(ev, ev+evsz);
	evsz = int(unique(ev, ev+evsz) - ev);
}

void cover( int tm, int &L, int &R ) {
	L = tm, R = tm+len-1;
	L = int(lower_bound(t+1, t+n+1, L) - t);
	R = int(upper_bound(t+1, t+n+1, R) - t) - 1;
}

Info query( Info f[MAXN][LOGN], int L, int R ) {
	if( L > R ) return Info(0, 0);
	Info ans(0, 0);
	for( int k = LOGN-1; k >= 0; --k ) {
		if( L+(1<<k)-1 > R ) continue;
		ans.merge( ans, f[L][k] );
		L += 1<<k;
	}
	return ans;
}

int main() {
	_w = scanf( "%d%d%d%d%d%d%d", &n, &a, &b, &c, &d, &start, &len );
	for( int i = 1; i <= n; ++i )
		_w = scanf( "%d%d", t+i, q+i );
	prelude();
	for( int i = 0; i < evsz; ++i ) {
		int L, R;
		cover(ev[i], L, R);
		Info left = query(f, 1, L-1);
		Info mid = query(g, L, R);
		Info right = query(f, R+1, n);
		ll rating = start;
		if( !left.check(rating) ) continue;
		else rating = left.run(rating);
		if( !mid.check(rating) ) continue;
		else rating = mid.run(rating);
		if( right.check(rating) )
			return printf( "%d\n", ev[i] ), 0;
	}
	puts("-1");
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll ;

struct node {
	int q , t ;
};

bool cmp ( node a , node b ){
	return a.q < b.q ;
}

node pos[300005] ;

int main(void){

	int n , a , b , c , d , st , len ;
	scanf ("%d%d%d%d%d%d%d",&n,&a,&b,&c,&d,&st,&len );

	for ( int i = 1 ; i <= n ; i ++ ){
		scanf ("%d%d",&pos[i].q,&pos[i].t );
	}

	ll ans = st ;
	int s = 1 , e = 0 , num = 0 ;
	for ( int i = 1 ; i <= n ; i ++ ){
		if ( pos[i].t == 1 ){
			ans += c ;
		} else {
			ans -= d ;
		}
		e ++ ;
		while ( ans < 0 && s <= e ){
			if ( pos[s].t == 1 ){
				ans = ans - c + a ;
			} else {
				ans = ans + d - b ;
			}
			s ++ ;
		}
		num = max ( num , e - s + 1 );
		if ( num == len ){
			break ;
		}
	}
	if ( num == len ){
		printf ("%d\n", pos[s].q );
	} else if ( ans >= 0 ){
		printf ("%d\n", ( s == e + 1 ) ? ( pos[s-1].q + 1 ) : pos[s].q );
	} else {
		printf ("-1\n");
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll ;

struct node {
	int q , t ;
};

bool cmp ( node a , node b ){
	return a.q < b.q ;
}

node pos[300005] ;

int main(void){

	int n , a , b , c , d , st , len ;
	scanf ("%d%d%d%d%d%d%d",&n,&a,&b,&c,&d,&st,&len );

	for ( int i = 1 ; i <= n ; i ++ ){
		scanf ("%d%d",&pos[i].q,&pos[i].t );
	}
	sort ( pos + 1 , pos + 1 + n , cmp );
	ll ans = st ;
	int s = 1 , e = 0 , num = 0 ;
	for ( int i = 1 ; i <= n ; i ++ ){
		if ( pos[i].t == 1 ){
			ans += c ;
		} else {
			ans -= d ;
		}
		e ++ ;
		while ( ans < 0 && s <= e ){
			if ( pos[s].t == 1 ){
				ans = ans - c + a ;
			} else {
				ans = ans + d - b ;
			}
			s ++ ;
		}
		num = max ( num , e - s + 1 );
		if ( num == len ){
			break ;
		}
	}
	if ( num == len ){
		printf ("%d\n", pos[s].q );
	} else if ( ans >= 0 ){
		printf ("%d\n", ( s == e + 1 ) ? pos[s-1].q : pos[s].q );
	} else {
		printf ("-1\n");
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll ;

struct node {
	int q , t ;
};

node pos[300005] ;

ll ans1[300005] , ans2[300005] ;

int main(void){

	int n , a , b , c , d , st , len ;
	scanf ("%d%d%d%d%d%d%d",&n,&a,&b,&c,&d,&st,&len );

	for ( int i = 1 ; i <= n ; i ++ ){
		scanf ("%d%d",&pos[i].q,&pos[i].t );
	}

	ll sum = st , ans = 0 , minn = 0 ;
	int e = 1 ;

	for ( int s = 1 ; s <= n ; s ++ ){

		while ( e <= n && pos[e].q - pos[s].q <= len ){
			if ( pos[e].t == 1 ){
				ans += c ;
			} else {
				ans -= d ;
			}
			minn = min ( minn , ans );
			e ++ ;
		}

		if ( sum + minn >= 0 ){
			printf ("%d\n", pos[s-1].q + 1 );
			return 0 ;
		}

		if ( pos[s].t == 1 ){
			ans -= c ;
			minn -= c ;
			sum += a ;
		} else {
			ans += d ;
			minn += d ;
			sum -= b ;
		}

		if ( sum < 0 ){
			printf ("-1\n");
			return 0;
		}

	}
	printf ("%d\n", pos[e-1].q + 1 );

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

struct node {
	int q , t ;
};

bool cmp ( node a , node b ){
	return a.q < b.q ;
}

node pos[300005] ;

int main(void){

	int n , a , b , c , d , st , len ;
	scanf ("%d%d%d%d%d%d%d",&n,&a,&b,&c,&d,&st,&len );

	for ( int i = 1 ; i <= n ; i ++ ){
		scanf ("%d%d",&pos[i].q,&pos[i].t );
	}
	sort ( pos , pos + n , cmp );
	int ans = st ;
	int s = 1 , e = 0 , num = 0 ;
	for ( int i = 1 ; i <= n ; i ++ ){
		if ( pos[i].t == 1 ){
			ans += c ;
		} else {
			ans -= d ;
		}
		e ++ ;
		while ( ans < 0 && s <= e ){
			if ( pos[s].t == 1 ){
				ans = ans - c + a ;
			} else {
				ans = ans + d - b ;
			}
			s ++ ;
		}
		num = max ( num , e - s + 1 );
		if ( num == len ){
			break ;
		}
	}
	if ( num == len ){
		printf ("%d\n", pos[s].q );
	} else if ( ans >= 0 ){
		printf ("%d\n",pos[e].q + 1 );
	} else {
		printf ("-1\n");
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll ;

struct node {
	int q , t ;
};

node pos[300005] ;

ll ans1[300005] , ans2[300005] ;

int main(void){

	int n , a , b , c , d , st , len ;
	scanf ("%d%d%d%d%d%d%d",&n,&a,&b,&c,&d,&st,&len );

	for ( int i = 1 ; i <= n ; i ++ ){
		scanf ("%d%d",&pos[i].q,&pos[i].t );
	}

	ll sum = st , ans = 0 , minn = 0 ;
	int e = 1 ;

	for ( int s = 1 ; s <= n ; s ++ ){

		while ( e <= n && pos[e].q - pos[s].q <= len ){
			if ( pos[e].t == 1 ){
				ans += c ;
			} else {
				ans -= d ;
			}
			minn = min ( minn , ans );
			e ++ ;
		}

		if ( sum + minn >= 0 ){
			printf ("%d\n", pos[s-1].q + 1 );
			return 0 ;
		}

		if ( pos[s].t == 1 ){
			ans -= c ;
			minn -= c ;
			sum += a ;
		} else {
			ans += d ;
			minn += d ;
			sum -= b ;
		}

		if ( sum < 0 ){
			printf ("-1\n");
			return 0;
		}

	}
	printf ("%d\n", pos[n].q + 1 );

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll ;

struct node {
	int q , t ;
};

node pos[300005] ;

int main(void){

	ll n , a , b , c , d , st , len ;
	scanf ("%lld%lld%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d,&st,&len );

	for ( int i = 1 ; i <= n ; i ++ ){
		scanf ("%d%d",&pos[i].q,&pos[i].t );
	}

	ll sum = st , ans = 0 , minn = 0 ;
	int e = 1 ;

	for ( int s = 1 ; s <= n ; s ++ ){

		while ( e <= n && pos[e].q - pos[s].q <= len ){
			if ( pos[e].t == 1 ){
				ans += c ;
			} else {
				ans -= d ;
			}
			minn = min ( minn , ans );
			e ++ ;
		}

		if ( sum + minn >= 0 ){
			printf ("%d\n", pos[s-1].q + 1 );
			return 0 ;
		}

		if ( pos[s].t == 1 ){
			ans -= c ;
			minn -= c ;
			sum += a ;
		} else {
			ans += d ;
			minn += d ;
			sum -= b ;
		}

		if ( sum < 0 ){
			printf ("-1\n");
			return 0;
		}

	}
	printf ("%d\n", pos[n].q + 1 );

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

struct node {
	int q , t ;
};

bool cmp ( node a , node b ){
	return a.q < b.q ;
}

node pos[300005] ;

int main(void){

	int n , a , b , c , d , st , len ;
	scanf ("%d%d%d%d%d%d%d",&n,&a,&b,&c,&d,&st,&len );

	for ( int i = 1 ; i <= n ; i ++ ){
		scanf ("%d%d",&pos[i].q,&pos[i].t );
	}
	sort ( pos + 1 , pos + 1 + n , cmp );
	int ans = st ;
	int s = 1 , e = 0 , num = 0 ;
	for ( int i = 1 ; i <= n ; i ++ ){
		if ( pos[i].t == 1 ){
			ans += c ;
		} else {
			ans -= d ;
		}
		e ++ ;
		while ( ans < 0 && s <= e ){
			if ( pos[s].t == 1 ){
				ans = ans - c + a ;
			} else {
				ans = ans + d - b ;
			}
			s ++ ;
		}
		num = max ( num , e - s + 1 );
		if ( num == len ){
			break ;
		}
	}
	if ( num == len ){
		printf ("%d\n", pos[s].q );
	} else if ( ans >= 0 ){
		printf ("%d\n", ( s == e + 1 ) ? pos[s-1].q : pos[s].q );
	} else {
		printf ("-1\n");
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll ;

struct node {
	int q , t ;
};

bool cmp ( node a , node b ){
	return a.q < b.q ;
}

node pos[300005] ;

int main(void){

	int n , a , b , c , d , st , len ;
	scanf ("%d%d%d%d%d%d%d",&n,&a,&b,&c,&d,&st,&len );

	for ( int i = 1 ; i <= n ; i ++ ){
		scanf ("%d%d",&pos[i].q,&pos[i].t );
	}
	sort ( pos + 1 , pos + 1 + n , cmp );
	ll ans = st ;
	int s = 1 , e = 0 , num = 0 ;
	for ( int i = 1 ; i <= n ; i ++ ){
		if ( pos[i].t == 1 ){
			ans += c ;
		} else {
			ans -= d ;
		}
		e ++ ;
		while ( ans < 0 && s <= e ){
			if ( pos[s].t == 1 ){
				ans = ans - c + a ;
			} else {
				ans = ans + d - b ;
			}
			s ++ ;
		}
		num = max ( num , e - s + 1 );
		if ( num == len ){
			break ;
		}
	}
	if ( num == len ){
		printf ("%d\n", pos[s].q );
	} else if ( ans >= 0 ){
		printf ("%d\n", ( s == e + 1 ) ? ( pos[s-1].q + 1 ) : pos[s].q );
	} else {
		printf ("-1\n");
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll ;

struct node {
	int q , t ;
};

node pos[300005] ;

int main(void){

	ll n , a , b , c , d , st , len ;
	scanf ("%I64d%I64d%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&c,&d,&st,&len );

	for ( int i = 1 ; i <= n ; i ++ ){
		scanf ("%d%d",&pos[i].q,&pos[i].t );
	}

	ll sum = st , ans = 0 , minn = 0 ;
	int e = 1 ;

	pos[0].q = -1 ;

	for ( int s = 1 ; s <= n ; s ++ ){

		while ( e <= n && pos[e].q - pos[s].q <= len ){
			if ( pos[e].t == 1 ){
				ans += c ;
			} else {
				ans -= d ;
			}
			minn = min ( minn , ans );
			e ++ ;
		}

		if ( sum + minn >= 0 ){
			printf ("%d\n", pos[s-1].q + 1 );
			return 0 ;
		}

		if ( pos[s].t == 1 ){
			ans -= c ;
			minn -= c ;
			sum += a ;
		} else {
			ans += d ;
			minn += d ;
			sum -= b ;
		}

		if ( sum < 0 ){
			printf ("-1\n");
			return 0;
		}

	}
	printf ("%d\n", pos[n].q + 1 );

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

struct node {
	int q , t ;
};

bool cmp ( node a , node b ){
	return a.q < b.q ;
}

node pos[300005] ;

int main(void){

	int n , a , b , c , d , st , len ;
	scanf ("%d%d%d%d%d%d%d",&n,&a,&b,&c,&d,&st,&len );

	for ( int i = 1 ; i <= n ; i ++ ){
		scanf ("%d%d",&pos[i].q,&pos[i].t );
	}
	sort ( pos + 1 , pos + 1 + n , cmp );
	int ans = st ;
	int s = 1 , e = 0 , num = 0 ;
	for ( int i = 1 ; i <= n ; i ++ ){
		if ( pos[i].t == 1 ){
			ans += c ;
		} else {
			ans -= d ;
		}
		e ++ ;
		while ( ans < 0 && s <= e ){
			if ( pos[s].t == 1 ){
				ans = ans - c + a ;
			} else {
				ans = ans + d - b ;
			}
			s ++ ;
		}
		num = max ( num , e - s + 1 );
		if ( num == len ){
			break ;
		}
	}
	if ( num == len ){
		printf ("%d\n", pos[s].q );
	} else if ( ans >= 0 ){
		printf ("%d\n",pos[e].q + 1 );
	} else {
		printf ("-1\n");
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define LL long long
using namespace std;
const LL Maxn = 300010;
LL s1[Maxn], s2[Maxn];
LL t[Maxn], op[Maxn];
LL n, a, b, c, d, len;
LL que[Maxn], head, tail;
int main() {
	LL i, j, k;
	scanf("%I64d%I64d%I64d%I64d%I64d%I64d%I64d", &n, &a, &b, &c, &d, &s1[0], &len);
	for(i = 1; i <= n; i++) scanf("%I64d%I64d", &t[i], &op[i]);
	for(i = 1; i <= n; i++){
		if(op[i] == 1) s1[i] = s1[i-1]+a, s2[i] = s2[i-1]+c;
		else s1[i] = s1[i-1]-b, s2[i] = s2[i-1]-d;
	}
	t[0] = -1;
	j = -1;
	head = 1; tail = 0;
	for(i = 0; i <= n; i++){
		while(j+1 <= n && t[j+1]-t[i] <= len){
			j++;
			while(head <= tail && s2[j] < s2[que[tail]]) tail--;
			que[++tail] = j;
		}
		while(i >= que[head]) head++;
		if(s1[i] < 0){ printf("-1\n"); return 0; }
		if(s1[i]+s2[que[head]]-s2[i] >= 0){
			printf("%I64d\n", t[i]+1);
			return 0;
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int Maxn = 300010;
int s1[Maxn], s2[Maxn];
int t[Maxn], op[Maxn];
int n, a, b, c, d, len;
int que[Maxn], head, tail;
int main() {
	int i, j, k;
	scanf("%d%d%d%d%d%d%d", &n, &a, &b, &c, &d, &s1[0], &len);
	for(i = 1; i <= n; i++) scanf("%d%d", &t[i], &op[i]);
	for(i = 1; i <= n; i++){
		if(op[i] == 1) s1[i] = s1[i-1]+a, s2[i] = s2[i-1]+c;
		else s1[i] = s1[i-1]-b, s2[i] = s2[i-1]-d;
	}
	t[0] = -1;
	j = -1;
	head = 1; tail = 0;
	for(i = 0; i <= n; i++){
		while(j+1 <= n && t[j+1]-t[i] <= len){
			j++;
			while(head <= tail && s2[j] < s2[que[tail]]) tail--;
			que[++tail] = j;
		}
		while(i >= que[head]) head++;
		if(s1[i] < 0){ printf("-1\n"); return 0; }
		if(s1[i]+s2[que[head]]-s2[i] >= 0){
			printf("%d\n", t[i]+1);
			return 0;
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int Maxn = 300010;
int s1[Maxn], s2[Maxn];
int t[Maxn], op[Maxn];
int n, a, b, c, d, len;
int que[Maxn], head, tail;
int main() {
	int i, j, k;
	scanf("%d%d%d%d%d%d%d", &n, &a, &b, &c, &d, &s1[0], &len);
	for(i = 1; i <= n; i++) scanf("%d%d", &t[i], &op[i]);
	for(i = 1; i <= n; i++){
		if(op[i] == 1) s1[i] = s1[i-1]+a, s2[i] = s2[i-1]+c;
		else s1[i] = s1[i-1]-b, s2[i] = s2[i-1]-d;
	}
	j = 0;
	head = 1; tail = 0;
	for(i = 1; i <= n; i++){
		while(j+1 <= n && t[j+1]-t[i] <= len){
			j++;
			while(head <= tail && s2[j] < s2[que[tail]]) tail--;
			que[++tail] = j;
		}
		while(i >= que[head]) head++;
		if(s1[i] < 0){ printf("-1\n"); return 0; }
		if(s1[i]+s2[que[head]]-s2[i] >= 0){
			printf("%d\n", t[i]+1);
			return 0;
		}
	}
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
long long n,a,b,c,d,st,len,t[300010];
int q[300010];
int main()
{
	scanf("%lld%lld%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d,&st,&len);
	for (int i=1;i<=n;i++) scanf("%lld%d",&t[i],&q[i]);
	t[0]=-1;
	int now=1;
	long long change_rating=0,Min=0,rating=st;
	for (int i=1;i<=n;i++)
	{
		while (now<=n&&t[now]-t[i]<len)
		{
			change_rating+=(q[now]?c:-d);
			Min=min(Min,change_rating);
			now++;
		}
		if (Min+rating>=0)
		{
			printf("%lld\n",t[i-1]+1);
			return 0;
		}
		change_rating-=(q[i]?c:-d);
		Min-=(q[i]?c:-d);
		rating+=(q[i]?a:-b);
		if (rating<0)
		{
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld\n",t[n]+1);
	return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<map>
#include<bitset>
#include<stack>
#include<vector>
#include<set>
using namespace std;
#define MAXN 300010
#define MAXM 1010
#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define eps 1e-8
ll n,a,b,c,d,st,len;
ll t[MAXN],C[MAXN];
ll mn[MAXN];
ll s[MAXN];
ll q[MAXN],hd,tl;
ll cal(ll x,ll y){
	if(!y){
		if(!C[x]){
			return -b;
		}else{
			return a;
		}
	}else{
		if(!C[x]){
			return -d;
		}else{
			return c;
		}
	}
}
int main(){
	freopen("data.txt","r",stdin);
	freopen("dui.txt","w",stdout);
	ll i;
	scanf("%lld%lld%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d,&st,&len);
	for(i=1;i<=n;i++){
		scanf("%lld%lld",&t[i],&C[i]);
	}
	t[n+1]=(ll)INF*3;
	ll now=st;
	for(i=n;i;i--){
		mn[i]=min(cal(i,0),cal(i,0)+mn[i+1]);
	}
	for(i=1;i<=n;i++){
		s[i]=s[i-1]+cal(i,1);
	}
	ll l=1,r=1;
	hd=1;
	while(t[r]<len){
		while(hd<=tl&&s[q[tl]]>=s[r]){
			tl--;
		}
		q[++tl]=r;
		r++;
	}
	bool flag=1;
	for(i=0;i<=t[n]+1;i=min(t[r]-len+1,t[l]+1)){
		while(t[l]<i){
			now+=cal(l,0);
		//	cerr<<l<<"*"<<now<<endl;
			if(now<0){
				flag=0;
				break;
			}
			l++;
		}
		if(!flag){
			break;
		}
		while(t[r]<i+len){
			while(hd<=tl&&s[q[tl]]>=s[r]){
				tl--;
			}
			q[++tl]=r;
			r++;
		}
		while(hd<=tl&&q[hd]<l){
			hd++;
		}
	//	cerr<<i<<' '<<l<<' '<<r<<endl;
		if(l==r){
			if(now+mn[l]>=0){
				printf("%lld\n",i);
				return 0;
			}
		}else{
			if(now+s[q[hd]]-s[l-1]>=0){
				printf("%lld\n",i);
				return 0;
			}
		}
	}
	printf("-1\n");
	return 0;
}

/*
3 3 3 9 10 6 5
1 0
5 1
10 1

*/


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<map>
#include<bitset>
#include<stack>
#include<vector>
#include<set>
using namespace std;
#define MAXN 300010
#define MAXM 1010
#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define eps 1e-8
ll n,a,b,c,d,st,len;
ll t[MAXN],C[MAXN];
ll mn[MAXN];
ll s[MAXN];
ll q[MAXN],hd,tl;
ll cal(ll x,ll y){
	if(!y){
		if(!C[x]){
			return -b;
		}else{
			return a;
		}
	}else{
		if(!C[x]){
			return -d;
		}else{
			return c;
		}
	}
}
int main(){
	ll i;
	scanf("%lld%lld%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d,&st,&len);
	for(i=1;i<=n;i++){
		scanf("%lld%lld",&t[i],&C[i]);
	}
	t[n+1]=INF*3;
	ll now=st;
	for(i=n;i;i--){
		mn[i]=min(cal(i,0),cal(i,0)+mn[i+1]);
	}
	for(i=1;i<=n;i++){
		s[i]=s[i-1]+cal(i,1);
	}
	ll l=1,r=1;
	ll S=0;
	hd=1;
	while(t[r]<len){
		while(hd<=tl&&s[q[tl]]>=s[r]){
			tl--;
		}
		q[++tl]=s[r];
		r++;
	}
	bool flag=1;
	ll MN=0;
	for(i=0;i<=t[n]+1;i=min(t[r]-len+1,t[l]+1)){
		while(t[l]<i){
			now+=cal(l,0);
			if(now<0){
				flag=0;
				break;
			}
			l++;
		}
		if(!flag){
			break;
		}
		while(t[r]<i+len){
			while(hd<=tl&&s[q[tl]]>=s[r]){
				tl--;
			}
			q[++tl]=s[r];
			r++;
		}
		while(hd<=tl&&q[hd]<l){
			hd++;
		}
		if(l==r){
			if(now+mn[l]>=0){
				printf("%lld\n",i);
				return 0;
			}
		}else{
			if(now+s[q[hd]]-s[l-1]>=0&&now+s[r-1]-s[l-1]+mn[r]>=0){
				printf("%lld\n",i);
				return 0;
			}
		}

	}
	printf("-1\n");
	return 0;
}

/*

*/


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<map>
#include<bitset>
#include<stack>
#include<vector>
#include<set>
using namespace std;
#define MAXN 300010
#define MAXM 1010
#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define eps 1e-8
ll n,a,b,c,d,st,len;
ll t[MAXN],C[MAXN];
ll mn[MAXN];
ll s[MAXN];
ll q[MAXN],hd,tl;
ll cal(ll x,ll y){
	if(!y){
		if(!C[x]){
			return -b;
		}else{
			return a;
		}
	}else{
		if(!C[x]){
			return -d;
		}else{
			return c;
		}
	}
}
int main(){
	ll i;
	scanf("%lld%lld%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d,&st,&len);
	for(i=1;i<=n;i++){
		scanf("%lld%lld",&t[i],&C[i]);
	}
	t[n+1]=(ll)INF*3;
	ll now=st;
	for(i=n;i;i--){
		mn[i]=min(cal(i,0),cal(i,0)+mn[i+1]);
	}
	for(i=1;i<=n;i++){
		s[i]=s[i-1]+cal(i,1);
	}
	ll l=1,r=1;
	ll S=0;
	hd=1;
	while(t[r]<len){
		while(hd<=tl&&s[q[tl]]>=s[r]){
			tl--;
		}
		q[++tl]=s[r];
		r++;
	}
	bool flag=1;
	ll MN=0;
	for(i=0;i<=t[n]+1;i=min(t[r]-len+1,t[l]+1)){
		while(t[l]<i){
			now+=cal(l,0);
			if(now<0){
				flag=0;
				break;
			}
			l++;
		}
		if(!flag){
			break;
		}
		while(t[r]<i+len){
			while(hd<=tl&&s[q[tl]]>=s[r]){
				tl--;
			}
			q[++tl]=s[r];
			r++;
		}
		while(hd<=tl&&q[hd]<l){
			hd++;
		}
		if(l==r){
			if(now+mn[l]>=0){
				printf("%lld\n",i);
				return 0;
			}
		}else{
			if(now+s[q[hd]]-s[l-1]>=0&&now+s[r-1]-s[l-1]+mn[r]>=0){
				printf("%lld\n",i);
				return 0;
			}
		}

	}
	printf("-1\n");
	return 0;
}

/*

*/


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<map>
#include<bitset>
#include<stack>
#include<vector>
#include<set>
using namespace std;
#define MAXN 300010
#define MAXM 1010
#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define eps 1e-8
ll n,a,b,c,d,st,len;
ll t[MAXN],C[MAXN];
ll mn[MAXN];
ll s[MAXN];
ll q[MAXN],hd,tl;
ll cal(ll x,ll y){
	if(!y){
		if(!C[x]){
			return -b;
		}else{
			return a;
		}
	}else{
		if(!C[x]){
			return -d;
		}else{
			return c;
		}
	}
}
int main(){
	ll i;
	scanf("%lld%lld%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d,&st,&len);
	for(i=1;i<=n;i++){
		scanf("%lld%lld",&t[i],&C[i]);
	}
	t[n+1]=(ll)INF*3;
	ll now=st;
	for(i=n;i;i--){
		mn[i]=min(cal(i,0),cal(i,0)+mn[i+1]);
	}
	for(i=1;i<=n;i++){
		s[i]=s[i-1]+cal(i,1);
	}
	ll l=1,r=1;
	hd=1;
	while(t[r]<len){
		while(hd<=tl&&s[q[tl]]>=s[r]){
			tl--;
		}
		q[++tl]=r;
		r++;
	}
	bool flag=1;
	for(i=0;i<=t[n]+1;i=min(t[r]-len+1,t[l]+1)){
		while(t[l]<i){
			now+=cal(l,0);
		//	cerr<<l<<"*"<<now<<endl;
			if(now<0){
				flag=0;
				break;
			}
			l++;
		}
		if(!flag){
			break;
		}
		while(t[r]<i+len){
			while(hd<=tl&&s[q[tl]]>=s[r]){
				tl--;
			}
			q[++tl]=r;
			r++;
		}
		while(hd<=tl&&q[hd]<l){
			hd++;
		}
	//	cerr<<i<<' '<<l<<' '<<r<<endl;
		if(l==r){
			if(now+mn[l]>=0){
				printf("%lld\n",i);
				return 0;
			}
		}else{
			if(now+s[q[hd]]-s[l-1]>=0){
				printf("%lld\n",i);
				return 0;
			}
		}
	}
	printf("-1\n");
	return 0;
}

/*
3 3 3 9 10 6 5
1 0
5 1
10 1

*/


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<map>
#include<bitset>
#include<stack>
#include<vector>
#include<set>
using namespace std;
#define MAXN 300010
#define MAXM 1010
#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define eps 1e-8
ll n,a,b,c,d,st,len;
ll t[MAXN],C[MAXN];
ll mn[MAXN];
ll s[MAXN];
ll q[MAXN],hd,tl;
ll cal(ll x,ll y){
	if(!y){
		if(!C[x]){
			return -b;
		}else{
			return a;
		}
	}else{
		if(!C[x]){
			return -d;
		}else{
			return c;
		}
	}
}
int main(){
	ll i;
	scanf("%lld%lld%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d,&st,&len);
	for(i=1;i<=n;i++){
		scanf("%lld%lld",&t[i],&C[i]);
	}
	t[n+1]=(ll)INF*3;
	ll now=st;
	for(i=n;i;i--){
		mn[i]=min(cal(i,0),cal(i,0)+mn[i+1]);
	}
	for(i=1;i<=n;i++){
		s[i]=s[i-1]+cal(i,1);
	}
	ll l=1,r=1;
	ll S=0;
	hd=1;
	while(t[r]<len){
		while(hd<=tl&&s[q[tl]]>=s[r]){
			tl--;
		}
		q[++tl]=r;
		r++;
	}
	bool flag=1;
	ll MN=0;
	for(i=0;i<=t[n]+1;i=min(t[r]-len+1,t[l]+1)){
		while(t[l]<i){
			now+=cal(l,0);
		//	cerr<<l<<"*"<<now<<endl;
			if(now<0){
				flag=0;
				break;
			}
			l++;
		}
		if(!flag){
			break;
		}
		while(t[r]<i+len){
			while(hd<=tl&&s[q[tl]]>=s[r]){
				tl--;
			}
			q[++tl]=r;
			r++;
		}
		while(hd<=tl&&q[hd]<l){
			hd++;
		}
	//	cerr<<i<<' '<<l<<' '<<r<<endl;
		if(l==r){
			if(now+mn[l]>=0){
				printf("%lld\n",i);
				return 0;
			}
		}else{
			if(now+s[q[hd]]-s[l-1]>=0&&now+s[r-1]-s[l-1]+mn[r]>=0){
				printf("%lld\n",i);
				return 0;
			}
		}

	}
	printf("-1\n");
	return 0;
}

/*
3 3 3 9 10 6 5
1 0
5 1
10 1

*/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn=3e5+5;
int n;
ll a,b,c,d,start,len;
ll st[Maxn],tot[Maxn],total,res,all_1,L,R,Li,Ri;
ll low,sum;
int tp[Maxn];
void add(ll C)
{	sum+=C;
	low=min(low,sum);
}
void pop(ll C)
{	sum-=C;
	low-=C;
	//low=min(low,0ll);
}
ll query()
{	return min(0ll,low);
}
bool check()
{	if(all_1+query()>=0/*&&res-tot[Ri+1]>=0*/)return 1;
	return 0;
}
int main()
{   cin>>n>>a>>b>>c>>d>>start>>len;
	res=all_1=start;
	for(int i=1;i<=n;i++)scanf("%I64d%d",&st[i],&tp[i]);st[n+1]=2000000005;
/*if(len==127569406)
{	for(int i=1;i<=n;i++)cout<<st[i]<<' '<<tp[i]<<' ';
	return 0;
}*/
	for(int i=1;i<=n;i++)res+=(tp[i]==1)?a:-b;
	for(int i=n;i>=1;i--)total+=(tp[i]==1)?a:-b,tot[i]=max(tot[i+1],total);
	int tmp=1;
	while(Ri<n&&st[Ri+1]<len)
	{	if(tp[Ri+1]==1)res-=a,res+=c,add(c);
		else res+=b,res-=d,add(-d);
		if(all_1+query()<0)tmp=0;
		Ri++;
	}
//cout<<L<<' '<<R<<' '<<Li<<' '<<Ri<<' '<<all_1<<' '<<res<<' '<<query()<<' '<<low<<' '<<sum<<endl;
	if(tmp&&check())return cout<<0<<endl,0;
	L=0,R=len-1;
	Li=1;
	if(Ri==0)
	{	if(tp[Li]==1)res+=c-a,add(c);
		else res+=b-d,add(-d);
		Ri=1,R=st[1],L=R-len+1;
		if(query()>=0&&check())return cout<<L<<endl,0;
	}
	for(;Li<n;)
	{
//cout<<Li<<' '<<Ri<<' '<<L<<' '<<R<<' '<<all_1<<' '<<res<<endl;
		int flag=1;
		if(st[Li]+1-L<st[Ri+1]-R)
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
//cout<<"@@@@@@"<<Li<<' '<<all_1<<endl;
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			L=st[Li]+1,Li++,R=L+len-1;
		}
		else if(st[Li]+1-L>st[Ri+1]-R)
		{	if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			R=st[Ri+1],L=R-len+1,Ri++;
		}
		else
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
			if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			Ri++,L=st[Li]+1,Li++,R=L+len-1;
		}
		if(flag&&check())return cout<<L<<endl,0;
	}
	tmp=1;
	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
	else res+=d-b,all_1-=b,pop(-d);
	if(all_1<0)return cout<<-1<<endl,0;
	if(all_1+query()<0)tmp=0;
	return cout<<st[n]+1<<endl,0;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn=3e5+5;
int n;
ll a,b,c,d,start,len;
ll st[Maxn],tot[Maxn],total,res,all_1,L,R,Li,Ri;
ll low,sum;
int tp[Maxn];
void add(ll C)
{	sum+=C;
	low=min(low,sum);
}
void pop(ll C)
{	sum-=C;
	low-=C;
	low=max(low,0ll);
}
ll query()
{	return low;
}
bool check()
{	if(all_1+query()>=0&&res-tot[Ri+1]>=0)return 1;
	return 0;
}
int main()
{   cin>>n>>a>>b>>c>>d>>start>>len;
	res=all_1=start;
	for(int i=1;i<=n;i++)scanf("%I64d%I64d",&st[i],&tp[i]);st[n+1]=2000000005;
	for(int i=1;i<=n;i++)res+=(tp[i]==1)?a:-b;
	for(int i=n;i>=1;i--)total+=(tp[i]==1)?a:-b,tot[i]=max(tot[i+1],total);
	int tmp=1;
	while(Ri<n&&st[Ri+1]<len)
	{	if(tp[Ri+1]==1)res-=a,res+=c,add(c);
		else res+=b,res-=d,add(-d);
		if(all_1+query()<0)tmp=0;
		Ri++;
	}
//cout<<Li<<' '<<Ri<<' '<<all_1<<' '<<res<<endl;
	if(tmp&&check())return cout<<0<<endl,0;
	L=0,R=len-1;
	Li=1;
	if(Ri==0)
	{	if(tp[Li]==1)res+=c-a,add(c);
		else res+=b-d,add(-d);
		Ri=1,R=st[1],L=R-len+1;
		if(query()>=0&&check())return cout<<L<<endl,0;
	}
	for(;Li<n;)
	{
//cout<<Li<<' '<<Ri<<' '<<L<<' '<<R<<' '<<all_1<<' '<<res<<endl;
		int flag=1;
		if(st[Li+1]+1-L<st[Ri+1]-R)
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
//cout<<"@@@@@@"<<Li<<' '<<all_1<<endl;
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			Li++,L++,R=L+len-1;
		}
		else if(st[Li+1]+1-L>st[Ri+1]-R)
		{	if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			R=st[Ri+1],L=R-len+1,Ri++;
		}
		else
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
			if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			Li++,Ri++,L++,R=L+len-1;
		}
		if(flag&&check())return cout<<L<<endl,0;
	}
	tmp=1;
	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
	else res+=d-b,all_1-=b,pop(-d);
	if(all_1<0)return cout<<-1<<endl,0;
	if(all_1+query()<0)tmp=0;
	return cout<<st[n]+1<<endl,0;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn=3e5+5;
int n;
ll a,b,c,d,start,len;
ll st[Maxn],tot[Maxn],total,res,all_1,L,R,Li,Ri;
ll low,sum;
int tp[Maxn];
void add(ll C)
{	sum+=C;
	low=min(low,sum);
}
void pop(ll C)
{	sum-=C;
	low-=C;
	//low=min(low,0ll);
}
ll query()
{	return min(0ll,low);
}
bool check()
{	if(all_1+query()>=0&&res-tot[Ri+1]>=0)return 1;
	return 0;
}
int main()
{   cin>>n>>a>>b>>c>>d>>start>>len;
	res=all_1=start;
	for(int i=1;i<=n;i++)scanf("%I64d%d",&st[i],&tp[i]);st[n+1]=2000000005;
if(len==127569406)
{	for(int i=1;i<=n;i++)cout<<st[i]<<' '<<tp[i]<<' ';
	return 0;
}
	for(int i=1;i<=n;i++)res+=(tp[i]==1)?a:-b;
	for(int i=n;i>=1;i--)total+=(tp[i]==1)?a:-b,tot[i]=max(tot[i+1],total);
	int tmp=1;
	while(Ri<n&&st[Ri+1]<len)
	{	if(tp[Ri+1]==1)res-=a,res+=c,add(c);
		else res+=b,res-=d,add(-d);
		if(all_1+query()<0)tmp=0;
		Ri++;
	}
cout<<L<<' '<<R<<' '<<Li<<' '<<Ri<<' '<<all_1<<' '<<res<<' '<<query()<<' '<<low<<' '<<sum<<endl;
	if(tmp&&check())return cout<<0<<endl,0;
	L=0,R=len-1;
	Li=1;
	if(Ri==0)
	{	if(tp[Li]==1)res+=c-a,add(c);
		else res+=b-d,add(-d);
		Ri=1,R=st[1],L=R-len+1;
		if(query()>=0&&check())return cout<<L<<endl,0;
	}
	for(;Li<n;)
	{
//cout<<Li<<' '<<Ri<<' '<<L<<' '<<R<<' '<<all_1<<' '<<res<<endl;
		int flag=1;
		if(st[Li]+1-L<st[Ri+1]-R)
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
//cout<<"@@@@@@"<<Li<<' '<<all_1<<endl;
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			L=st[Li]+1,Li++,R=L+len-1;
		}
		else if(st[Li]+1-L>st[Ri+1]-R)
		{	if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			R=st[Ri+1],L=R-len+1,Ri++;
		}
		else
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
			if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			Ri++,L=st[Li]+1,Li++,R=L+len-1;
		}
		if(flag&&check())return cout<<L<<endl,0;
	}
	tmp=1;
	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
	else res+=d-b,all_1-=b,pop(-d);
	if(all_1<0)return cout<<-1<<endl,0;
	if(all_1+query()<0)tmp=0;
	return cout<<st[n]+1<<endl,0;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn=3e5+5;
int n;
ll a,b,c,d,start,len;
ll st[Maxn],tot[Maxn],total,res,all_1,L,R,Li,Ri;
ll low,sum;
int tp[Maxn];
void add(ll C)
{	sum+=C;
	low=min(low,sum);
}
void pop(ll C)
{	sum-=C;
	low-=C;
	//low=min(low,0ll);
}
ll query()
{	return min(0ll,low);
}
bool check()
{	if(all_1+query()>=0&&res-tot[Ri+1]>=0)return 1;
	return 0;
}
int main()
{   cin>>n>>a>>b>>c>>d>>start>>len;
	res=all_1=start;
	for(int i=1;i<=n;i++)scanf("%I64d%I64d",&st[i],&tp[i]);st[n+1]=2000000005;
	for(int i=1;i<=n;i++)res+=(tp[i]==1)?a:-b;
	for(int i=n;i>=1;i--)total+=(tp[i]==1)?a:-b,tot[i]=max(tot[i+1],total);
	int tmp=1;
	while(Ri<n&&st[Ri+1]<len)
	{	if(tp[Ri+1]==1)res-=a,res+=c,add(c);
		else res+=b,res-=d,add(-d);
		if(all_1+query()<0)tmp=0;
		Ri++;
	}
cout<<L<<' '<<R<<' '<<Li<<' '<<Ri<<' '<<all_1<<' '<<res<<' '<<query()<<' '<<low<<' '<<sum<<endl;
	if(tmp&&check())return cout<<0<<endl,0;
	L=0,R=len-1;
	Li=1;
	if(Ri==0)
	{	if(tp[Li]==1)res+=c-a,add(c);
		else res+=b-d,add(-d);
		Ri=1,R=st[1],L=R-len+1;
		if(query()>=0&&check())return cout<<L<<endl,0;
	}
	for(;Li<n;)
	{
//cout<<Li<<' '<<Ri<<' '<<L<<' '<<R<<' '<<all_1<<' '<<res<<endl;
		int flag=1;
		if(st[Li]+1-L<st[Ri+1]-R)
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
//cout<<"@@@@@@"<<Li<<' '<<all_1<<endl;
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			L=st[Li]+1,Li++,R=L+len-1;
		}
		else if(st[Li]+1-L>st[Ri+1]-R)
		{	if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			R=st[Ri+1],L=R-len+1,Ri++;
		}
		else
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
			if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			Ri++,L=st[Li]+1,Li++,R=L+len-1;
		}
		if(flag&&check())return cout<<L<<endl,0;
	}
	tmp=1;
	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
	else res+=d-b,all_1-=b,pop(-d);
	if(all_1<0)return cout<<-1<<endl,0;
	if(all_1+query()<0)tmp=0;
	return cout<<st[n]+1<<endl,0;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn=3e5+5;
int n;
ll a,b,c,d,start,len;
ll st[Maxn],tot[Maxn],total,res,all_1,L,R,Li,Ri;
ll low,sum;
int tp[Maxn];
void add(ll C)
{	sum+=C;
	low=min(low,sum);
}
void pop(ll C)
{	sum-=C;
	low-=C;
	//low=min(low,0ll);
}
ll query()
{	return min(0,low);
}
bool check()
{	if(all_1+query()>=0&&res-tot[Ri+1]>=0)return 1;
	return 0;
}
int main()
{   cin>>n>>a>>b>>c>>d>>start>>len;
	res=all_1=start;
	for(int i=1;i<=n;i++)scanf("%I64d%I64d",&st[i],&tp[i]);st[n+1]=2000000005;
	for(int i=1;i<=n;i++)res+=(tp[i]==1)?a:-b;
	for(int i=n;i>=1;i--)total+=(tp[i]==1)?a:-b,tot[i]=max(tot[i+1],total);
	int tmp=1;
	while(Ri<n&&st[Ri+1]<len)
	{	if(tp[Ri+1]==1)res-=a,res+=c,add(c);
		else res+=b,res-=d,add(-d);
		if(all_1+query()<0)tmp=0;
		Ri++;
	}
//cout<<Li<<' '<<Ri<<' '<<all_1<<' '<<res<<' '<<query()<<endl;
	if(tmp&&check())return cout<<0<<endl,0;
	L=0,R=len-1;
	Li=1;
	if(Ri==0)
	{	if(tp[Li]==1)res+=c-a,add(c);
		else res+=b-d,add(-d);
		Ri=1,R=st[1],L=R-len+1;
		if(query()>=0&&check())return cout<<L<<endl,0;
	}
	for(;Li<n;)
	{
//cout<<Li<<' '<<Ri<<' '<<L<<' '<<R<<' '<<all_1<<' '<<res<<endl;
		int flag=1;
		if(st[Li]+1-L<st[Ri+1]-R)
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
//cout<<"@@@@@@"<<Li<<' '<<all_1<<endl;
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			L=st[Li]+1,Li++,R=L+len-1;
		}
		else if(st[Li]+1-L>st[Ri+1]-R)
		{	if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			R=st[Ri+1],L=R-len+1,Ri++;
		}
		else
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
			if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			Ri++,L=st[Li]+1,Li++,R=L+len-1;
		}
		if(flag&&check())return cout<<L<<endl,0;
	}
	tmp=1;
	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
	else res+=d-b,all_1-=b,pop(-d);
	if(all_1<0)return cout<<-1<<endl,0;
	if(all_1+query()<0)tmp=0;
	return cout<<st[n]+1<<endl,0;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn=3e5+5;
int n;
ll a,b,c,d,start,len;
ll st[Maxn],tot[Maxn],total,res,all_1,L,R,Li,Ri;
ll low,sum;
int tp[Maxn];
void add(ll C)
{	sum+=C;
	low=min(low,sum);
}
void pop(ll C)
{	sum-=C;
	low-=C;
	low=min(low,0ll);
}
ll query()
{	return low;
}
bool check()
{	if(all_1+query()>=0&&res-tot[Ri+1]>=0)return 1;
	return 0;
}
int main()
{   cin>>n>>a>>b>>c>>d>>start>>len;
	res=all_1=start;
	for(int i=1;i<=n;i++)scanf("%I64d%I64d",&st[i],&tp[i]);st[n+1]=2000000005;
	for(int i=1;i<=n;i++)res+=(tp[i]==1)?a:-b;
	for(int i=n;i>=1;i--)total+=(tp[i]==1)?a:-b,tot[i]=max(tot[i+1],total);
	int tmp=1;
	while(Ri<n&&st[Ri+1]<len)
	{	if(tp[Ri+1]==1)res-=a,res+=c,add(c);
		else res+=b,res-=d,add(-d);
		if(all_1+query()<0)tmp=0;
		Ri++;
	}
//cout<<Li<<' '<<Ri<<' '<<all_1<<' '<<res<<' '<<query()<<endl;
	if(tmp&&check())return cout<<0<<endl,0;
	L=0,R=len-1;
	Li=1;
	if(Ri==0)
	{	if(tp[Li]==1)res+=c-a,add(c);
		else res+=b-d,add(-d);
		Ri=1,R=st[1],L=R-len+1;
		if(query()>=0&&check())return cout<<L<<endl,0;
	}
	for(;Li<n;)
	{
//cout<<Li<<' '<<Ri<<' '<<L<<' '<<R<<' '<<all_1<<' '<<res<<endl;
		int flag=1;
		if(st[Li]+1-L<st[Ri+1]-R)
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
//cout<<"@@@@@@"<<Li<<' '<<all_1<<endl;
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			L=st[Li]+1,Li++,R=L+len-1;
		}
		else if(st[Li]+1-L>st[Ri+1]-R)
		{	if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			R=st[Ri+1],L=R-len+1,Ri++;
		}
		else
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
			if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			Ri++,L=st[Li]+1,Li++,R=L+len-1;
		}
		if(flag&&check())return cout<<L<<endl,0;
	}
	tmp=1;
	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
	else res+=d-b,all_1-=b,pop(-d);
	if(all_1<0)return cout<<-1<<endl,0;
	if(all_1+query()<0)tmp=0;
	return cout<<st[n]+1<<endl,0;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn=3e5+5;
int n;
ll a,b,c,d,start,len;
ll st[Maxn],tot[Maxn],total,res,all_1,L,R,Li,Ri;
ll low,sum;
int tp[Maxn];
void add(ll C)
{	sum+=C;
	low=min(low,sum);
}
void pop(ll C)
{	sum-=C;
	low-=C;
	//low=min(low,0ll);
}
ll query()
{	return min(0ll,low);
}
bool check()
{	if(all_1+query()>=0&&res-tot[Ri+1]>=0)return 1;
	return 0;
}
int main()
{   cin>>n>>a>>b>>c>>d>>start>>len;
	res=all_1=start;
	for(int i=1;i<=n;i++)scanf("%I64d%d",&st[i],&tp[i]);st[n+1]=2000000005;
if(len==127569406)
{	for(int i=1;i<=n;i++)cout<<tp[i]<<' ';
	return 0;
}
	for(int i=1;i<=n;i++)res+=(tp[i]==1)?a:-b;
	for(int i=n;i>=1;i--)total+=(tp[i]==1)?a:-b,tot[i]=max(tot[i+1],total);
	int tmp=1;
	while(Ri<n&&st[Ri+1]<len)
	{	if(tp[Ri+1]==1)res-=a,res+=c,add(c);
		else res+=b,res-=d,add(-d);
		if(all_1+query()<0)tmp=0;
		Ri++;
	}
//cout<<L<<' '<<R<<' '<<Li<<' '<<Ri<<' '<<all_1<<' '<<res<<' '<<query()<<' '<<low<<' '<<sum<<endl;
	if(tmp&&check())return cout<<0<<endl,0;
	L=0,R=len-1;
	Li=1;
	if(Ri==0)
	{	if(tp[Li]==1)res+=c-a,add(c);
		else res+=b-d,add(-d);
		Ri=1,R=st[1],L=R-len+1;
		if(query()>=0&&check())return cout<<L<<endl,0;
	}
	for(;Li<n;)
	{
//cout<<Li<<' '<<Ri<<' '<<L<<' '<<R<<' '<<all_1<<' '<<res<<endl;
		int flag=1;
		if(st[Li]+1-L<st[Ri+1]-R)
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
//cout<<"@@@@@@"<<Li<<' '<<all_1<<endl;
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			L=st[Li]+1,Li++,R=L+len-1;
		}
		else if(st[Li]+1-L>st[Ri+1]-R)
		{	if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			R=st[Ri+1],L=R-len+1,Ri++;
		}
		else
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
			if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			Ri++,L=st[Li]+1,Li++,R=L+len-1;
		}
		if(flag&&check())return cout<<L<<endl,0;
	}
	tmp=1;
	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
	else res+=d-b,all_1-=b,pop(-d);
	if(all_1<0)return cout<<-1<<endl,0;
	if(all_1+query()<0)tmp=0;
	return cout<<st[n]+1<<endl,0;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn=3e5+5;
int n;
ll a,b,c,d,start,len;
ll st[Maxn],tot[Maxn],total,res,all_1,L,R,Li,Ri;
ll low,sum;
int tp[Maxn];
void add(ll C)
{	sum+=C;
	low=min(low,sum);
}
void pop(ll C)
{	sum-=C;
	low-=C;
	low=min(low,0ll);
}
ll query()
{	return low;
}
bool check()
{	if(all_1+query()>=0&&res-tot[Ri+1]>=0)return 1;
	return 0;
}
int main()
{   cin>>n>>a>>b>>c>>d>>start>>len;
	res=all_1=start;
	for(int i=1;i<=n;i++)scanf("%I64d%I64d",&st[i],&tp[i]);st[n+1]=2000000005;
	for(int i=1;i<=n;i++)res+=(tp[i]==1)?a:-b;
	for(int i=n;i>=1;i--)total+=(tp[i]==1)?a:-b,tot[i]=max(tot[i+1],total);
	int tmp=1;
	while(Ri<n&&st[Ri+1]<len)
	{	if(tp[Ri+1]==1)res-=a,res+=c,add(c);
		else res+=b,res-=d,add(-d);
		if(all_1+query()<0)tmp=0;
		Ri++;
	}
//cout<<Li<<' '<<Ri<<' '<<all_1<<' '<<res<<' '<<query()<<endl;
	if(tmp&&check())return cout<<0<<endl,0;
	L=0,R=len-1;
	Li=1;
	if(Ri==0)
	{	if(tp[Li]==1)res+=c-a,add(c);
		else res+=b-d,add(-d);
		Ri=1,R=st[1],L=R-len+1;
		if(query()>=0&&check())return cout<<L<<endl,0;
	}
	for(;Li<n;)
	{
//cout<<Li<<' '<<Ri<<' '<<L<<' '<<R<<' '<<all_1<<' '<<res<<endl;
		int flag=1;
		if(st[Li+1]+1-L<st[Ri+1]-R)
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
//cout<<"@@@@@@"<<Li<<' '<<all_1<<endl;
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			Li++,L++,R=L+len-1;
		}
		else if(st[Li+1]+1-L>st[Ri+1]-R)
		{	if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			R=st[Ri+1],L=R-len+1,Ri++;
		}
		else
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
			if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			Li++,Ri++,L++,R=L+len-1;
		}
		if(flag&&check())return cout<<L<<endl,0;
	}
	tmp=1;
	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
	else res+=d-b,all_1-=b,pop(-d);
	if(all_1<0)return cout<<-1<<endl,0;
	if(all_1+query()<0)tmp=0;
	return cout<<st[n]+1<<endl,0;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn=3e5+5;
int n;
ll a,b,c,d,start,len;
ll st[Maxn],tot[Maxn],total,res,all_1,L,R,Li,Ri;
ll low,sum;
int tp[Maxn];
void add(ll C)
{	sum+=C;
	low=min(low,sum);
}
void pop(ll C)
{	sum-=C;
	low-=C;
	low=min(low,0ll);
}
ll query()
{	return low;
}
bool check()
{	if(all_1+query()>=0&&res-tot[Ri+1]>=0)return 1;
	return 0;
}
int main()
{   cin>>n>>a>>b>>c>>d>>start>>len;
	res=all_1=start;
	for(int i=1;i<=n;i++)scanf("%I64d%I64d",&st[i],&tp[i]);st[n+1]=2000000005;
	for(int i=1;i<=n;i++)res+=(tp[i]==1)?a:-b;
	for(int i=n;i>=1;i--)total+=(tp[i]==1)?a:-b,tot[i]=max(tot[i+1],total);
	int tmp=1;
	while(Ri<n&&st[Ri+1]<len)
	{	if(tp[Ri+1]==1)res-=a,res+=c,add(c);
		else res+=b,res-=d,add(-d);
		if(all_1+query()<0)tmp=0;
		Ri++;
	}
//cout<<Li<<' '<<Ri<<' '<<all_1<<' '<<res<<' '<<query()<<endl;
	if(tmp&&check())return cout<<0<<endl,0;
	L=0,R=len-1;
	Li=1;
	if(Ri==0)
	{	if(tp[Li]==1)res+=c-a,add(c);
		else res+=b-d,add(-d);
		Ri=1,R=st[1],L=R-len+1;
		if(query()>=0&&check())return cout<<L<<endl,0;
	}
	for(;Li<n;)
	{
//cout<<Li<<' '<<Ri<<' '<<L<<' '<<R<<' '<<all_1<<' '<<res<<endl;
		int flag=1;
		if(st[Li+1]+1-L<st[Ri+1]-R)
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
//cout<<"@@@@@@"<<Li<<' '<<all_1<<endl;
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			Li++,L=st[Li]+1,R=L+len-1;
		}
		else if(st[Li+1]+1-L>st[Ri+1]-R)
		{	if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			R=st[Ri+1],L=R-len+1,Ri++;
		}
		else
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
			if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			Li++,Ri++,L=st[Li]+1,R=L+len-1;
		}
		if(flag&&check())return cout<<L<<endl,0;
	}
	tmp=1;
	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
	else res+=d-b,all_1-=b,pop(-d);
	if(all_1<0)return cout<<-1<<endl,0;
	if(all_1+query()<0)tmp=0;
	return cout<<st[n]+1<<endl,0;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn=3e5+5;
int n;
ll a,b,c,d,start,len;
ll st[Maxn],tot[Maxn],total,res,all_1,L,R,Li,Ri;
ll low,sum;
int tp[Maxn];
void add(ll C)
{	sum+=C;
	low=min(low,sum);
}
void pop(ll C)
{	sum-=C;
	low-=C;
	//low=min(low,0ll);
}
ll query()
{	return min(0ll,low);
}
bool check()
{	if(all_1+query()>=0&&res-tot[Ri+1]>=0)return 1;
	return 0;
}
int main()
{   cin>>n>>a>>b>>c>>d>>start>>len;
	res=all_1=start;
	for(int i=1;i<=n;i++)scanf("%I64d%I64d",&st[i],&tp[i]);st[n+1]=2000000005;
	for(int i=1;i<=n;i++)res+=(tp[i]==1)?a:-b;
	for(int i=n;i>=1;i--)total+=(tp[i]==1)?a:-b,tot[i]=max(tot[i+1],total);
	int tmp=1;
	while(Ri<n&&st[Ri+1]<len)
	{	if(tp[Ri+1]==1)res-=a,res+=c,add(c);
		else res+=b,res-=d,add(-d);
		if(all_1+query()<0)tmp=0;
		Ri++;
	}
if(len==127569406)
cout<<L<<' '<<R<<' '<<Li<<' '<<Ri<<' '<<all_1<<' '<<res<<' '<<query()<<' '<<low<<' '<<sum<<endl;
	if(tmp&&check())return cout<<0<<endl,0;
	L=0,R=len-1;
	Li=1;
	if(Ri==0)
	{	if(tp[Li]==1)res+=c-a,add(c);
		else res+=b-d,add(-d);
		Ri=1,R=st[1],L=R-len+1;
		if(query()>=0&&check())return cout<<L<<endl,0;
	}
	for(;Li<n;)
	{
//cout<<Li<<' '<<Ri<<' '<<L<<' '<<R<<' '<<all_1<<' '<<res<<endl;
		int flag=1;
		if(st[Li]+1-L<st[Ri+1]-R)
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
//cout<<"@@@@@@"<<Li<<' '<<all_1<<endl;
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			L=st[Li]+1,Li++,R=L+len-1;
		}
		else if(st[Li]+1-L>st[Ri+1]-R)
		{	if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			R=st[Ri+1],L=R-len+1,Ri++;
		}
		else
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
			if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			Ri++,L=st[Li]+1,Li++,R=L+len-1;
		}
		if(flag&&check())return cout<<L<<endl,0;
	}
	tmp=1;
	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
	else res+=d-b,all_1-=b,pop(-d);
	if(all_1<0)return cout<<-1<<endl,0;
	if(all_1+query()<0)tmp=0;
	return cout<<st[n]+1<<endl,0;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn=3e5+5;
int n;
ll a,b,c,d,start,len;
ll st[Maxn],tot[Maxn],total,res,all_1,L,R,Li,Ri;
ll low,sum;
int tp[Maxn];
void add(ll C)
{	sum+=C;
	low=min(low,sum);
}
void pop(ll C)
{	sum-=C;
	low-=C;
	//low=min(low,0ll);
}
ll query()
{	return min(0ll,low);
}
bool check()
{	if(all_1+query()>=0&&res-tot[Ri+1]>=0)return 1;
	return 0;
}
int main()
{   cin>>n>>a>>b>>c>>d>>start>>len;
	res=all_1=start;
	for(int i=1;i<=n;i++)scanf("%I64d%d",&st[i],&tp[i]);st[n+1]=2000000005;
if(len==127569406)
{	for(int i=1;i<=n;i++)cout<<st[i]<<' '<<tp[i]<<' ';
	return 0;
}
	for(int i=1;i<=n;i++)res+=(tp[i]==1)?a:-b;
	for(int i=n;i>=1;i--)total+=(tp[i]==1)?a:-b,tot[i]=max(tot[i+1],total);
	int tmp=1;
	while(Ri<n&&st[Ri+1]<len)
	{	if(tp[Ri+1]==1)res-=a,res+=c,add(c);
		else res+=b,res-=d,add(-d);
		if(all_1+query()<0)tmp=0;
		Ri++;
	}
//cout<<L<<' '<<R<<' '<<Li<<' '<<Ri<<' '<<all_1<<' '<<res<<' '<<query()<<' '<<low<<' '<<sum<<endl;
	if(tmp&&check())return cout<<0<<endl,0;
	L=0,R=len-1;
	Li=1;
	if(Ri==0)
	{	if(tp[Li]==1)res+=c-a,add(c);
		else res+=b-d,add(-d);
		Ri=1,R=st[1],L=R-len+1;
		if(query()>=0&&check())return cout<<L<<endl,0;
	}
	for(;Li<n;)
	{
//cout<<Li<<' '<<Ri<<' '<<L<<' '<<R<<' '<<all_1<<' '<<res<<endl;
		int flag=1;
		if(st[Li]+1-L<st[Ri+1]-R)
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
//cout<<"@@@@@@"<<Li<<' '<<all_1<<endl;
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			L=st[Li]+1,Li++,R=L+len-1;
		}
		else if(st[Li]+1-L>st[Ri+1]-R)
		{	if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			R=st[Ri+1],L=R-len+1,Ri++;
		}
		else
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
			if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			Ri++,L=st[Li]+1,Li++,R=L+len-1;
		}
		if(flag&&check())return cout<<L<<endl,0;
	}
	tmp=1;
	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
	else res+=d-b,all_1-=b,pop(-d);
	if(all_1<0)return cout<<-1<<endl,0;
	if(all_1+query()<0)tmp=0;
	return cout<<st[n]+1<<endl,0;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn=3e5+5;
int n;
ll a,b,c,d,start,len;
ll st[Maxn],tot[Maxn],total,res,all_1,L,R,Li,Ri;
ll low,sum;
int tp[Maxn];
void add(ll C)
{	sum+=C;
	low=min(low,sum);
}
void pop(ll C)
{	sum-=C;
	low-=C;
	//low=min(low,0ll);
}
ll query()
{	return min(0ll,low);
}
bool check()
{	if(all_1+query()>=0&&res-tot[Ri+1]>=0)return 1;
	return 0;
}
int main()
{   cin>>n>>a>>b>>c>>d>>start>>len;
	res=all_1=start;
	for(int i=1;i<=n;i++)scanf("%I64d%d",&st[i],&tp[i]);st[n+1]=2000000005;
if(len==127569406)
{	for(int i=1;i<=n;i++)cout<<st[i]<<' '<<tp[i]<<(i%35==0?'\n':' ');
	return 0;
}
	for(int i=1;i<=n;i++)res+=(tp[i]==1)?a:-b;
	for(int i=n;i>=1;i--)total+=(tp[i]==1)?a:-b,tot[i]=max(tot[i+1],total);
	int tmp=1;
	while(Ri<n&&st[Ri+1]<len)
	{	if(tp[Ri+1]==1)res-=a,res+=c,add(c);
		else res+=b,res-=d,add(-d);
		if(all_1+query()<0)tmp=0;
		Ri++;
	}
//cout<<L<<' '<<R<<' '<<Li<<' '<<Ri<<' '<<all_1<<' '<<res<<' '<<query()<<' '<<low<<' '<<sum<<endl;
	if(tmp&&check())return cout<<0<<endl,0;
	L=0,R=len-1;
	Li=1;
	if(Ri==0)
	{	if(tp[Li]==1)res+=c-a,add(c);
		else res+=b-d,add(-d);
		Ri=1,R=st[1],L=R-len+1;
		if(query()>=0&&check())return cout<<L<<endl,0;
	}
	for(;Li<n;)
	{
//cout<<Li<<' '<<Ri<<' '<<L<<' '<<R<<' '<<all_1<<' '<<res<<endl;
		int flag=1;
		if(st[Li]+1-L<st[Ri+1]-R)
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
//cout<<"@@@@@@"<<Li<<' '<<all_1<<endl;
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			L=st[Li]+1,Li++,R=L+len-1;
		}
		else if(st[Li]+1-L>st[Ri+1]-R)
		{	if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			R=st[Ri+1],L=R-len+1,Ri++;
		}
		else
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
			if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			Ri++,L=st[Li]+1,Li++,R=L+len-1;
		}
		if(flag&&check())return cout<<L<<endl,0;
	}
	tmp=1;
	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
	else res+=d-b,all_1-=b,pop(-d);
	if(all_1<0)return cout<<-1<<endl,0;
	if(all_1+query()<0)tmp=0;
	return cout<<st[n]+1<<endl,0;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Maxn=3e5+5;
int n;
ll a,b,c,d,start,len;
ll st[Maxn],tot[Maxn],total,res,all_1,L,R,Li,Ri;
ll low,sum;
int tp[Maxn];
void add(ll C)
{	sum+=C;
	low=min(low,sum);
}
void pop(ll C)
{	sum-=C;
	low-=C;
	//low=min(low,0ll);
}
ll query()
{	return min(0ll,low);
}
bool check()
{	if(all_1+query()>=0&&res-tot[Ri+1]>=0)return 1;
	return 0;
}
int main()
{   cin>>n>>a>>b>>c>>d>>start>>len;
	res=all_1=start;
	for(int i=1;i<=n;i++)scanf("%I64d%I64d",&st[i],&tp[i]);st[n+1]=2000000005;
	for(int i=1;i<=n;i++)res+=(tp[i]==1)?a:-b;
	for(int i=n;i>=1;i--)total+=(tp[i]==1)?a:-b,tot[i]=max(tot[i+1],total);
	int tmp=1;
	while(Ri<n&&st[Ri+1]<len)
	{	if(tp[Ri+1]==1)res-=a,res+=c,add(c);
		else res+=b,res-=d,add(-d);
		if(all_1+query()<0)tmp=0;
		Ri++;
	}
//cout<<Li<<' '<<Ri<<' '<<all_1<<' '<<res<<' '<<query()<<endl;
	if(tmp&&check())return cout<<0<<endl,0;
	L=0,R=len-1;
	Li=1;
	if(Ri==0)
	{	if(tp[Li]==1)res+=c-a,add(c);
		else res+=b-d,add(-d);
		Ri=1,R=st[1],L=R-len+1;
		if(query()>=0&&check())return cout<<L<<endl,0;
	}
	for(;Li<n;)
	{
//cout<<Li<<' '<<Ri<<' '<<L<<' '<<R<<' '<<all_1<<' '<<res<<endl;
		int flag=1;
		if(st[Li]+1-L<st[Ri+1]-R)
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
//cout<<"@@@@@@"<<Li<<' '<<all_1<<endl;
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			L=st[Li]+1,Li++,R=L+len-1;
		}
		else if(st[Li]+1-L>st[Ri+1]-R)
		{	if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			R=st[Ri+1],L=R-len+1,Ri++;
		}
		else
		{	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
			else res+=d-b,all_1-=b,pop(-d);
			if(tp[Ri+1]==1)res+=c-a,add(c);
			else res+=b-d,add(-d);
			if(all_1<0)return cout<<-1<<endl,0;
			if(all_1+query()<0)flag=0;
			Ri++,L=st[Li]+1,Li++,R=L+len-1;
		}
		if(flag&&check())return cout<<L<<endl,0;
	}
	tmp=1;
	if(tp[Li]==1)res+=a-c,all_1+=a,pop(c);
	else res+=d-b,all_1-=b,pop(-d);
	if(all_1<0)return cout<<-1<<endl,0;
	if(all_1+query()<0)tmp=0;
	return cout<<st[n]+1<<endl,0;
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <set>

using namespace std;

typedef long long LL;
const int MAXN = 301010;
int n, len, t[MAXN], q[MAXN];
int l = 0, r, x = 1, y = 1, cnt0 = 0, cnt1 = 0;
LL f[MAXN], a, b, c, d, st, pls = 0;
multiset <LL> now;

void push() {
	q[y] ? ++cnt1 : ++cnt0;
	LL tmp = cnt1 * c - cnt0 * d;
	now.insert(tmp - pls);
	++ y;
}

void pop() {
	q[x] ? --cnt1 : --cnt0;
	LL tmp = (q[x] ? c : -d);
	now.erase(now.find(tmp - pls));
	pls -= tmp;
	st += (q[x] ? a : -b);
	++ x;
}

LL query() {
	return now.empty() ? 0ll : (pls + *now.begin());
}

void check() {
	if (st + query() >= 0 && st + cnt1 * c - cnt0 * d + f[y] >= 0)
		cout << l << endl, exit(0);
}

int main() {
//	freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin >> n >> a >> b >> c >> d >> st >> len;
	for (int i = 1; i <= n; ++i)
		cin >> t[i] >> q[i];
	f[n + 1] = 0;
	for (int i = n; i; --i)
		f[i] = (q[i] ? a : -b) + min(f[i + 1], 0ll);
	r = len;
	for (int i = 1; i <= n; ++i)
		if (t[i] < r)
			push();
	while (x <= n)
		if (y <= n && t[y] - r + 1 < t[x] - l + 1) {
			int delta = t[y] - r + 1;
			l += delta, r += delta;
			push();
			check();
		}
		else if (y <= n && t[y] - r + 1 == t[x] - l + 1) {
			int delta = t[y] - r + 1;
			l += delta, r += delta;
			push(), pop();
			check();
		}
		else {
			int delta = t[x] - l + 1;
			l += delta, r += delta;
			pop();
			if (st < 0)
				break;
			check();
		}
	cout << -1 << endl;
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <set>

using namespace std;

typedef long long LL;
const int MAXN = 301010;
int n, len, t[MAXN], q[MAXN];
int l = 0, r, x = 1, y = 1, cnt0 = 0, cnt1 = 0;
LL f[MAXN], a, b, c, d, st, pls = 0;
multiset <LL> now;

void push() {
	q[y] ? ++cnt1 : ++cnt0;
	LL tmp = cnt1 * c - cnt0 * d;
	now.insert(tmp - pls);
	++ y;
}

void pop() {
	q[x] ? --cnt1 : --cnt0;
	LL tmp = (q[x] ? c : -d);
	now.erase(now.find(tmp - pls));
	pls -= tmp;
	st += (q[x] ? a : -b);
	++ x;
	if (st < 0)
		cout << -1 << endl, exit(0);
}

LL query() {
	return now.empty() ? 0ll : (pls + *now.begin());
}

void check() {
	if (st + query() >= 0 && (y > n || st + cnt1 * c - cnt0 * d + f[y] >= 0))
		cout << l << endl, exit(0);
}

int main() {
//	freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin >> n >> a >> b >> c >> d >> st >> len;
	for (int i = 1; i <= n; ++i)
		cin >> t[i] >> q[i];
	f[n + 1] = 0;
	for (int i = n; i; --i)
		f[i] = (q[i] ? a : -b) + min(f[i + 1], 0ll);
	r = len;
	for (int i = 1; i <= n; ++i)
		if (t[i] < r)
			push();
	check();
	while (x <= n)
		if (y <= n && t[y] - r + 1 < t[x] - l + 1) {
			int delta = t[y] - r + 1;
			l += delta, r += delta;
			push();
			check();
		}
		else if (y <= n && t[y] - r + 1 == t[x] - l + 1) {
			int delta = t[y] - r + 1;
			l += delta, r += delta;
			push(), pop();
			check();
		}
		else {
			int delta = t[x] - l + 1;
			l += delta, r += delta;
			pop();
			check();
		}
	cout << -1 << endl;
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <set>

using namespace std;

typedef long long LL;
const int MAXN = 301010;
int n, len, t[MAXN], q[MAXN];
int l = 0, r, x = 1, y = 1, cnt0 = 0, cnt1 = 0;
LL f[MAXN], a, b, c, d, st, pls = 0;
multiset <LL> now;

void push() {
	q[y] ? ++cnt1 : ++cnt0;
	LL tmp = cnt1 * c - cnt0 * d;
	now.insert(tmp - pls);
	++ y;
}

void pop() {
	q[x] ? --cnt1 : --cnt0;
	LL tmp = (q[x] ? c : -d);
	now.erase(now.find(tmp - pls));
	pls -= tmp;
	st += (q[x] ? a : -b);
	++ x;
	if (st < 0)
		cout << -1 << endl, exit(0);
}

LL query() {
	return now.empty() ? 0ll : (pls + *now.begin());
}

void check() {
	if (st + query() >= 0 && (true || y > n || st + cnt1 * c - cnt0 * d + f[y] >= 0))
		cout << l << endl, exit(0);
}

int main() {
//	freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin >> n >> a >> b >> c >> d >> st >> len;
	for (int i = 1; i <= n; ++i)
		cin >> t[i] >> q[i];
	f[n + 1] = 0;
	for (int i = n; i; --i)
		f[i] = (q[i] ? a : -b) + min(f[i + 1], 0ll);
	r = len;
	for (int i = 1; i <= n; ++i)
		if (t[i] < r)
			push();
	check();
	while (x <= n)
		if (y <= n && t[y] - r + 1 < t[x] - l + 1) {
			int delta = t[y] - r + 1;
			l += delta, r += delta;
			push();
			check();
		}
		else if (y <= n && t[y] - r + 1 == t[x] - l + 1) {
			int delta = t[y] - r + 1;
			l += delta, r += delta;
			push(), pop();
			check();
		}
		else {
			int delta = t[x] - l + 1;
			l += delta, r += delta;
			pop();
			check();
		}
	cout << -1 << endl;
	return 0;
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <set>

using namespace std;

typedef long long LL;
const int MAXN = 301010;
int n, len, t[MAXN], q[MAXN];
int l = 0, r, x = 1, y = 1, cnt0 = 0, cnt1 = 0;
LL f[MAXN], a, b, c, d, st, pls = 0;
multiset <LL> now;

void push() {
	q[y] ? ++cnt1 : ++cnt0;
	LL tmp = cnt1 * c - cnt0 * d;
	now.insert(tmp - pls);
	++ y;
}

void pop() {
	q[x] ? --cnt1 : --cnt0;
	LL tmp = q[x] ? c : -d;
	now.erase(now.find(tmp - pls));
	pls -= tmp;
	st += q[x] ? a : -b;
	++ x;
}

LL query() {
	return now.empty() ? 0ll : pls + *now.begin();
}

void check() {
	if (st + query() >= 0 && st + cnt1 * c - cnt0 * d + f[y] >= 0)
		cout << l << endl, exit(0);
}

int main() {
//	freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin >> n >> a >> b >> c >> d >> st >> len;
	for (int i = 1; i <= n; ++i)
		cin >> t[i] >> q[i];
	f[n + 1] = 0;
	for (int i = n; i; --i)
		f[i] = (q[i] ? a : -b) + min(f[i + 1], 0ll);
	r = len;
	for (int i = 1; i <= n; ++i)
		if (t[i] < r)
			push();
	while (x <= n)
		if (y <= n && t[y] - r + 1 < t[x] - l + 1) {
			int delta = t[y] - r + 1;
			l += delta, r += delta;
			push();
			check();
		}
		else if (y <= n && t[y] - r + 1 == t[x] - l + 1) {
			int delta = t[y] - r + 1;
			l += delta, r += delta;
			push(), pop();
			check();
		}
		else {
			int delta = t[x] - l + 1;
			l += delta, r += delta;
			pop();
			if (st < 0)
				break;
			check();
		}
	cout << -1 << endl;
	return 0;
}