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

public class icpc
{
    public static void main(String[] args) throws IOException
    {
//        Reader in = new Reader();
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s1[] = in.readLine().split(" ");
        int n = Integer.parseInt(s1[0]);
        int p = Integer.parseInt(s1[1]);
        String s = in.readLine();
        StringBuilder stringBuilder = new StringBuilder();
        int i = 0;
        if(p == 1)
        {
            System.out.println("NO");
        }
        else if(p == 2 && n > 1)
        {
            System.out.println("NO");
        }
        else
        {
            outer: for (i = n - 1;i>=0;i--)
            {
                int x = s.charAt(i) - 'a';
                if (x == p - 1)
                    continue;
                else
                {
                    for (int j = x + 1;j < p;j++)
                    {
                        char c = (char)(j + 97);
                        if ((i - 1 >= 0 && s.charAt(i - 1) != c && i - 2 >= 0 && s.charAt(i - 2) != c) || i  == 0)
                        {
                            stringBuilder.append(s.substring(0, i));
                            stringBuilder.append(c);
                            stringBuilder.append(s.substring(i + 1));
                            break outer;
                        }
                    }
                }
            }
            if(i == -1)
            {
                System.out.println("NO");
            }
            else
            {
                for (int j = i + 1;j< n;j++)
                {
                    for (int k = 0;k<p;k++)
                    {
                        char c = (char)(k + 97);
                        if(j - 1 >= 0 && stringBuilder.charAt(j - 1) != c && j - 2 >= 0 && stringBuilder.charAt(j - 2) != c)
                        {
                            stringBuilder.setCharAt(j, c);
                            break;
                        }
                    }
                }
                System.out.println(stringBuilder);
            }
        }
    }
}
class NumberTheory
{
    public boolean isPrime(long n)
    {
        if(n < 2)
            return false;
        for(long x = 2;x * x <= n;x++)
        {
            if(n % x == 0)
                return false;
        }
        return true;
    }
    public ArrayList<Integer> primeFactorisation(int n)
    {
        ArrayList<Integer> f = new ArrayList<>();
        for(int x=2;x * x <= n;x++)
        {
            while(n % x == 0)
            {
                f.add(x);
                n /= x;
            }
        }
        if(n > 1)
            f.add(n);
        return f;
    }
    public int[] sieveOfEratosthenes(int n)
    {
        int[] sieve = new int[n + 1];
        for(int x=2;x<=n;x++)
        {
            if(sieve[x] != 0)
                continue;
            sieve[x] = x;
            for(int u=2*x;u<=n;u+=x)
                if(sieve[u] == 0)
                    sieve[u] = x;
        }
        return sieve;
    }
    public long gcd(long a, long b)
    {
        if(b == 0)
            return a;
        return gcd(b, a % b);
    }
    public long phi(long n)
    {
        double result = n;

        for(long p=2;p*p<=n;p++)
        {
            if(n % p == 0)
            {
                while (n % p == 0)
                    n /= p;
                result *= (1.0 - (1.0 / (double)p));
            }
        }
        if(n > 1)
            result *= (1.0 - (1.0 / (double)n));
        return (long)result;
    }
    public Name extendedEuclid(long a, long b)
    {
        if(b == 0)
            return new Name(a, 1, 0);
        Name n1 = extendedEuclid(b, a % b);
        Name n2 = new Name(n1.d, n1.y, n1.x - (long)Math.floor((double)a / b) * n1.y);
        return n2;
    }
    public long modularExponentiation(long a, long b, long n)
    {
        long d = 1L;
        String bString = Long.toBinaryString(b);
        for(int i=0;i<bString.length();i++)
        {
            d = (d * d) % n;
            if(bString.charAt(i) == '1')
                d = (d * a) % n;
        }
        return d;
    }
}
class Name
{
    long d;
    long x;
    long y;

    public Name(long d, long x, long y)
    {
        this.d = d;
        this.x = x;
        this.y = y;
    }
}
class SuffixArray
{
    int ALPHABET_SZ = 256, N;
    int[] T, lcp, sa, sa2, rank, tmp, c;

    public SuffixArray(String str)
    {
        this(toIntArray(str));
    }

    private static int[] toIntArray(String s)
    {
        int[] text = new int[s.length()];
        for (int i = 0; i < s.length(); i++) text[i] = s.charAt(i);
        return text;
    }

    public SuffixArray(int[] text)
    {
        T = text;
        N = text.length;
        sa = new int[N];
        sa2 = new int[N];
        rank = new int[N];
        c = new int[Math.max(ALPHABET_SZ, N)];
        construct();
        kasai();
    }

    private void construct()
    {
        int i, p, r;
        for (i = 0; i < N; ++i) c[rank[i] = T[i]]++;
        for (i = 1; i < ALPHABET_SZ; ++i) c[i] += c[i - 1];
        for (i = N - 1; i >= 0; --i) sa[--c[T[i]]] = i;
        for (p = 1; p < N; p <<= 1)
        {
            for (r = 0, i = N - p; i < N; ++i) sa2[r++] = i;
            for (i = 0; i < N; ++i) if (sa[i] >= p) sa2[r++] = sa[i] - p;
            Arrays.fill(c, 0, ALPHABET_SZ, 0);
            for (i = 0; i < N; ++i) c[rank[i]]++;
            for (i = 1; i < ALPHABET_SZ; ++i) c[i] += c[i - 1];
            for (i = N - 1; i >= 0; --i) sa[--c[rank[sa2[i]]]] = sa2[i];
            for (sa2[sa[0]] = r = 0, i = 1; i < N; ++i)
            {
                if (!(rank[sa[i - 1]] == rank[sa[i]]
                        && sa[i - 1] + p < N
                        && sa[i] + p < N
                        && rank[sa[i - 1] + p] == rank[sa[i] + p])) r++;
                sa2[sa[i]] = r;
            }
            tmp = rank;
            rank = sa2;
            sa2 = tmp;
            if (r == N - 1) break;
            ALPHABET_SZ = r + 1;
        }
    }

    private void kasai()
    {
        lcp = new int[N];
        int[] inv = new int[N];
        for (int i = 0; i < N; i++) inv[sa[i]] = i;
        for (int i = 0, len = 0; i < N; i++)
        {
            if (inv[i] > 0)
            {
                int k = sa[inv[i] - 1];
                while ((i + len < N) && (k + len < N) && T[i + len] == T[k + len]) len++;
                lcp[inv[i] - 1] = len;
                if (len > 0) len--;
            }
        }
    }
}
class ZAlgorithm
{
    public int[] calculateZ(char input[])
    {
        int Z[] = new int[input.length];
        int left = 0;
        int right = 0;
        for(int k = 1; k < input.length; k++) {
            if(k > right) {
                left = right = k;
                while(right < input.length && input[right] == input[right - left]) {
                    right++;
                }
                Z[k] = right - left;
                right--;
            } else {
                //we are operating inside box
                int k1 = k - left;
                //if value does not stretches till right bound then just copy it.
                if(Z[k1] < right - k + 1) {
                    Z[k] = Z[k1];
                } else { //otherwise try to see if there are more matches.
                    left = k;
                    while(right < input.length && input[right] == input[right - left]) {
                        right++;
                    }
                    Z[k] = right - left;
                    right--;
                }
            }
        }
        return Z;
    }
    public ArrayList<Integer> matchPattern(char text[], char pattern[])
    {
        char newString[] = new char[text.length + pattern.length + 1];
        int i = 0;
        for(char ch : pattern) {
            newString[i] = ch;
            i++;
        }
        newString[i] = '$';
        i++;
        for(char ch : text) {
            newString[i] = ch;
            i++;
        }
        ArrayList<Integer> result = new ArrayList<>();
        int Z[] = calculateZ(newString);

        for(i = 0; i < Z.length ; i++) {
            if(Z[i] == pattern.length) {
                result.add(i - pattern.length - 1);
            }
        }
        return result;
    }
}
class KMPAlgorithm
{
    public int[] computeTemporalArray(char[] pattern)
    {
        int[] lps = new int[pattern.length];

        int index = 0;
        for(int i=1;i<pattern.length;)
        {
            if(pattern[i] == pattern[index])
            {
                lps[i] = index + 1;
                index++;
                i++;
            }
            else
            {
                if(index != 0)
                {
                    index = lps[index - 1];
                }
                else
                {
                    lps[i] = 0;
                    i++;
                }
            }
        }
        return lps;
    }

    public ArrayList<Integer> KMPMatcher(char[] text, char[] pattern)
    {
        int[] lps = computeTemporalArray(pattern);

        int j = 0;
        int i = 0;
        int n = text.length;
        int m = pattern.length;
        ArrayList<Integer> indices = new ArrayList<>();
        while(i < n)
        {
            if(pattern[j] == text[i])
            {
                i++;
                j++;
            }
            if(j == m)
            {
                indices.add(i - j);
                j = lps[j - 1];
            }
            else if(i < n && pattern[j] != text[i])
            {
                if(j != 0)
                    j = lps[j - 1];
                else
                    i = i + 1;
            }
        }
        return indices;
    }
}
class Hashing
{
    public long[] computePowers(long p, int n, long m)
    {
        long[] powers = new long[n];
        powers[0] = 1;
        for(int i=1;i<n;i++)
        {
            powers[i] = (powers[i - 1] * p) % m;
        }
        return powers;
    }
    public long computeHash(String s)
    {
        long p = 31;
        long m = 1_000_000_009;
        long hashValue = 0L;
        long[] powers = computePowers(p, s.length(), m);
        for(int i=0;i<s.length();i++)
        {
            char ch = s.charAt(i);
            hashValue = (hashValue + (ch - 'a' + 1) * powers[i]) % m;
        }
        return hashValue;
    }
}
class BasicFunctions
{
    public long min(long[] A)
    {
        long min = Long.MAX_VALUE;
        for(int i=0;i<A.length;i++)
        {
            min = Math.min(min, A[i]);
        }
        return min;
    }
    public long max(long[] A)
    {
        long max = Long.MAX_VALUE;
        for(int i=0;i<A.length;i++)
        {
            max = Math.max(max, A[i]);
        }
        return max;
    }
}
class Matrix
{
    long a;
    long b;
    long c;
    long d;

    public Matrix(long a, long b, long c, long d)
    {
        this.a = a;
        this.b = b;
        this.c = c;
        this.d = d;
    }
}
class MergeSortInt
{
    // Merges two subarrays of arr[].
    // First subarray is arr[l..m]
    // Second subarray is arr[m+1..r]
    void merge(int arr[], int l, int m, int r) {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        int L[] = new int[n1];
        int R[] = new int[n2];

        /*Copy data to temp arrays*/
        for (int i = 0; i < n1; ++i)
            L[i] = arr[l + i];
        for (int j = 0; j < n2; ++j)
            R[j] = arr[m + 1 + j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2) {
            if (L[i] <= R[j]) {
                arr[k] = L[i];
                i++;
            } else {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1) {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2) {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    void sort(int arr[], int l, int r) {
        if (l < r) {
            // Find the middle point
            int m = (l + r) / 2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr, m + 1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }

}
class MergeSortLong
{
    // Merges two subarrays of arr[].
    // First subarray is arr[l..m]
    // Second subarray is arr[m+1..r]
    void merge(long arr[], int l, int m, int r) {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        long L[] = new long[n1];
        long R[] = new long[n2];

        /*Copy data to temp arrays*/
        for (int i = 0; i < n1; ++i)
            L[i] = arr[l + i];
        for (int j = 0; j < n2; ++j)
            R[j] = arr[m + 1 + j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2) {
            if (L[i] <= R[j]) {
                arr[k] = L[i];
                i++;
            } else {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1) {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2) {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    void sort(long arr[], int l, int r) {
        if (l < r) {
            // Find the middle point
            int m = (l + r) / 2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr, m + 1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }
}
class Node
{
    String a;
    String b;
    Node(String s1,String s2)
    {
        this.a = s1;
        this.b = s2;
    }
    @Override
    public boolean equals(Object ob)
    {
        if(ob == null)
            return false;
        if(!(ob instanceof Node))
            return false;
        if(ob == this)
            return true;
        Node obj = (Node)ob;
        if(this.a.equals(obj.a) && this.b.equals(obj.b))
            return true;
        return false;
    }

    @Override
    public int hashCode()
    {
        return (int)this.a.length();
    }
}
class Reader
{
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader()
    {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException
    {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException
    {
        byte[] buf = new byte[64]; // line length
        int cnt = 0, c;
        while ((c = read()) != -1)
        {
            if (c == '\n')
                break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException
    {
        int ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do
        {
            ret = ret * 10 + c - '0';
        }  while ((c = read()) >= '0' && c <= '9');

        if (neg)
            return -ret;
        return ret;
    }

    public long nextLong() throws IOException
    {
        long ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');
        if (neg)
            return -ret;
        return ret;
    }

    public double nextDouble() throws IOException
    {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();

        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');

        if (c == '.')
        {
            while ((c = read()) >= '0' && c <= '9')
            {
                ret += (c - '0') / (div *= 10);
            }
        }

        if (neg)
            return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException
    {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1)
            buffer[0] = -1;
    }

    private byte read() throws IOException
    {
        if (bufferPointer == bytesRead)
            fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException
    {
        if (din == null)
            return;
        din.close();
    }
}
class FenwickTree
{
    public void update(long[] fenwickTree,long delta,int index)
    {
        index += 1;
        while(index < fenwickTree.length)
        {
            fenwickTree[index] += delta;
            index = index + (index & (-index));
        }
    }
    public long prefixSum(long[] fenwickTree,int index)
    {
        long sum = 0L;
        index += 1;
        while(index > 0)
        {
            sum += fenwickTree[index];
            index -= (index & (-index));
        }
        return sum;
    }
}
class SegmentTree
{
    public int nextPowerOfTwo(int num)
    {
        if(num == 0)
            return 1;
        if(num > 0 && (num & (num - 1)) == 0)
            return num;
        while((num &(num - 1)) > 0)
        {
            num = num & (num - 1);
        }
        return num << 1;
    }
    public int[] createSegmentTree(int[] input)
    {
        int np2 = nextPowerOfTwo(input.length);
        int[] segmentTree = new int[np2 * 2 - 1];

        for(int i=0;i<segmentTree.length;i++)
            segmentTree[i] = Integer.MIN_VALUE;

        constructSegmentTree(segmentTree,input,0,input.length-1,0);
        return segmentTree;

    }
    private void constructSegmentTree(int[] segmentTree,int[] input,int low,int high,int pos)
    {
        if(low == high)
        {
            segmentTree[pos] = input[low];
            return;
        }
        int mid = (low + high)/ 2;
        constructSegmentTree(segmentTree,input,low,mid,2*pos + 1);
        constructSegmentTree(segmentTree,input,mid+1,high,2*pos + 2);
        segmentTree[pos] = Math.max(segmentTree[2*pos + 1],segmentTree[2*pos + 2]);
    }
    public int rangeMinimumQuery(int []segmentTree,int qlow,int qhigh,int len)
    {
        return rangeMinimumQuery(segmentTree,0,len-1,qlow,qhigh,0);
    }
    private int rangeMinimumQuery(int segmentTree[],int low,int high,int qlow,int qhigh,int pos)
    {
        if(qlow <= low && qhigh >= high){
            return segmentTree[pos];
        }
        if(qlow > high || qhigh < low){
            return Integer.MIN_VALUE;
        }
        int mid = (low+high)/2;
        return Math.max(rangeMinimumQuery(segmentTree, low, mid, qlow, qhigh, 2 * pos + 1),
                rangeMinimumQuery(segmentTree, mid + 1, high, qlow, qhigh, 2 * pos + 2));
    }
}


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

public class icpc
{
    public static void main(String[] args) throws IOException
    {
//        Reader in = new Reader();
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s1[] = in.readLine().split(" ");
        int n = Integer.parseInt(s1[0]);
        int p = Integer.parseInt(s1[1]);
        String s = in.readLine();
        StringBuilder stringBuilder = new StringBuilder();
        int i = 0;
        if(p == 1)
        {
            System.out.println("NO");
        }
        else
        {
            outer: for (i = n - 1;i>=0;i--)
            {
                int x = s.charAt(i) - 'a';
                if (x == p - 1)
                    continue;
                else
                {
                    for (int j = x + 1;j < p;j++)
                    {
                        char c = (char)(j + 97);
                        if ((i - 1 >= 0 && s.charAt(i - 1) != c && i - 2 >= 0 && s.charAt(i - 2) != c) || i  == 0)
                        {
                            stringBuilder.append(s.substring(0, i));
                            stringBuilder.append(c);
                            stringBuilder.append(s.substring(i + 1));
                            break outer;
                        }
                    }
                }
            }
            if(i == -1)
            {
                System.out.println("NO");
            }
            else
            {
                for (int j = i + 1;j< n;j++)
                {
                    for (int k = 0;k<p;k++)
                    {
                        char c = (char)(k + 97);
                        if(j - 1 >= 0 && stringBuilder.charAt(j - 1) != c && j - 2 >= 0 && stringBuilder.charAt(j - 2) != c)
                        {
                            stringBuilder.setCharAt(j, c);
                            break;
                        }
                        else if(j - 1 >= 0 && stringBuilder.charAt(j - 1) != c)
                        {
                            stringBuilder.setCharAt(j, c);
                            break;
                        }
                        else
                            continue;
                    }
                }
                System.out.println(stringBuilder);
            }
        }
    }
}
class NumberTheory
{
    public boolean isPrime(long n)
    {
        if(n < 2)
            return false;
        for(long x = 2;x * x <= n;x++)
        {
            if(n % x == 0)
                return false;
        }
        return true;
    }
    public ArrayList<Integer> primeFactorisation(int n)
    {
        ArrayList<Integer> f = new ArrayList<>();
        for(int x=2;x * x <= n;x++)
        {
            while(n % x == 0)
            {
                f.add(x);
                n /= x;
            }
        }
        if(n > 1)
            f.add(n);
        return f;
    }
    public int[] sieveOfEratosthenes(int n)
    {
        int[] sieve = new int[n + 1];
        for(int x=2;x<=n;x++)
        {
            if(sieve[x] != 0)
                continue;
            sieve[x] = x;
            for(int u=2*x;u<=n;u+=x)
                if(sieve[u] == 0)
                    sieve[u] = x;
        }
        return sieve;
    }
    public long gcd(long a, long b)
    {
        if(b == 0)
            return a;
        return gcd(b, a % b);
    }
    public long phi(long n)
    {
        double result = n;

        for(long p=2;p*p<=n;p++)
        {
            if(n % p == 0)
            {
                while (n % p == 0)
                    n /= p;
                result *= (1.0 - (1.0 / (double)p));
            }
        }
        if(n > 1)
            result *= (1.0 - (1.0 / (double)n));
        return (long)result;
    }
    public Name extendedEuclid(long a, long b)
    {
        if(b == 0)
            return new Name(a, 1, 0);
        Name n1 = extendedEuclid(b, a % b);
        Name n2 = new Name(n1.d, n1.y, n1.x - (long)Math.floor((double)a / b) * n1.y);
        return n2;
    }
    public long modularExponentiation(long a, long b, long n)
    {
        long d = 1L;
        String bString = Long.toBinaryString(b);
        for(int i=0;i<bString.length();i++)
        {
            d = (d * d) % n;
            if(bString.charAt(i) == '1')
                d = (d * a) % n;
        }
        return d;
    }
}
class Name
{
    long d;
    long x;
    long y;

    public Name(long d, long x, long y)
    {
        this.d = d;
        this.x = x;
        this.y = y;
    }
}
class SuffixArray
{
    int ALPHABET_SZ = 256, N;
    int[] T, lcp, sa, sa2, rank, tmp, c;

    public SuffixArray(String str)
    {
        this(toIntArray(str));
    }

    private static int[] toIntArray(String s)
    {
        int[] text = new int[s.length()];
        for (int i = 0; i < s.length(); i++) text[i] = s.charAt(i);
        return text;
    }

    public SuffixArray(int[] text)
    {
        T = text;
        N = text.length;
        sa = new int[N];
        sa2 = new int[N];
        rank = new int[N];
        c = new int[Math.max(ALPHABET_SZ, N)];
        construct();
        kasai();
    }

    private void construct()
    {
        int i, p, r;
        for (i = 0; i < N; ++i) c[rank[i] = T[i]]++;
        for (i = 1; i < ALPHABET_SZ; ++i) c[i] += c[i - 1];
        for (i = N - 1; i >= 0; --i) sa[--c[T[i]]] = i;
        for (p = 1; p < N; p <<= 1)
        {
            for (r = 0, i = N - p; i < N; ++i) sa2[r++] = i;
            for (i = 0; i < N; ++i) if (sa[i] >= p) sa2[r++] = sa[i] - p;
            Arrays.fill(c, 0, ALPHABET_SZ, 0);
            for (i = 0; i < N; ++i) c[rank[i]]++;
            for (i = 1; i < ALPHABET_SZ; ++i) c[i] += c[i - 1];
            for (i = N - 1; i >= 0; --i) sa[--c[rank[sa2[i]]]] = sa2[i];
            for (sa2[sa[0]] = r = 0, i = 1; i < N; ++i)
            {
                if (!(rank[sa[i - 1]] == rank[sa[i]]
                        && sa[i - 1] + p < N
                        && sa[i] + p < N
                        && rank[sa[i - 1] + p] == rank[sa[i] + p])) r++;
                sa2[sa[i]] = r;
            }
            tmp = rank;
            rank = sa2;
            sa2 = tmp;
            if (r == N - 1) break;
            ALPHABET_SZ = r + 1;
        }
    }

    private void kasai()
    {
        lcp = new int[N];
        int[] inv = new int[N];
        for (int i = 0; i < N; i++) inv[sa[i]] = i;
        for (int i = 0, len = 0; i < N; i++)
        {
            if (inv[i] > 0)
            {
                int k = sa[inv[i] - 1];
                while ((i + len < N) && (k + len < N) && T[i + len] == T[k + len]) len++;
                lcp[inv[i] - 1] = len;
                if (len > 0) len--;
            }
        }
    }
}
class ZAlgorithm
{
    public int[] calculateZ(char input[])
    {
        int Z[] = new int[input.length];
        int left = 0;
        int right = 0;
        for(int k = 1; k < input.length; k++) {
            if(k > right) {
                left = right = k;
                while(right < input.length && input[right] == input[right - left]) {
                    right++;
                }
                Z[k] = right - left;
                right--;
            } else {
                //we are operating inside box
                int k1 = k - left;
                //if value does not stretches till right bound then just copy it.
                if(Z[k1] < right - k + 1) {
                    Z[k] = Z[k1];
                } else { //otherwise try to see if there are more matches.
                    left = k;
                    while(right < input.length && input[right] == input[right - left]) {
                        right++;
                    }
                    Z[k] = right - left;
                    right--;
                }
            }
        }
        return Z;
    }
    public ArrayList<Integer> matchPattern(char text[], char pattern[])
    {
        char newString[] = new char[text.length + pattern.length + 1];
        int i = 0;
        for(char ch : pattern) {
            newString[i] = ch;
            i++;
        }
        newString[i] = '$';
        i++;
        for(char ch : text) {
            newString[i] = ch;
            i++;
        }
        ArrayList<Integer> result = new ArrayList<>();
        int Z[] = calculateZ(newString);

        for(i = 0; i < Z.length ; i++) {
            if(Z[i] == pattern.length) {
                result.add(i - pattern.length - 1);
            }
        }
        return result;
    }
}
class KMPAlgorithm
{
    public int[] computeTemporalArray(char[] pattern)
    {
        int[] lps = new int[pattern.length];

        int index = 0;
        for(int i=1;i<pattern.length;)
        {
            if(pattern[i] == pattern[index])
            {
                lps[i] = index + 1;
                index++;
                i++;
            }
            else
            {
                if(index != 0)
                {
                    index = lps[index - 1];
                }
                else
                {
                    lps[i] = 0;
                    i++;
                }
            }
        }
        return lps;
    }

    public ArrayList<Integer> KMPMatcher(char[] text, char[] pattern)
    {
        int[] lps = computeTemporalArray(pattern);

        int j = 0;
        int i = 0;
        int n = text.length;
        int m = pattern.length;
        ArrayList<Integer> indices = new ArrayList<>();
        while(i < n)
        {
            if(pattern[j] == text[i])
            {
                i++;
                j++;
            }
            if(j == m)
            {
                indices.add(i - j);
                j = lps[j - 1];
            }
            else if(i < n && pattern[j] != text[i])
            {
                if(j != 0)
                    j = lps[j - 1];
                else
                    i = i + 1;
            }
        }
        return indices;
    }
}
class Hashing
{
    public long[] computePowers(long p, int n, long m)
    {
        long[] powers = new long[n];
        powers[0] = 1;
        for(int i=1;i<n;i++)
        {
            powers[i] = (powers[i - 1] * p) % m;
        }
        return powers;
    }
    public long computeHash(String s)
    {
        long p = 31;
        long m = 1_000_000_009;
        long hashValue = 0L;
        long[] powers = computePowers(p, s.length(), m);
        for(int i=0;i<s.length();i++)
        {
            char ch = s.charAt(i);
            hashValue = (hashValue + (ch - 'a' + 1) * powers[i]) % m;
        }
        return hashValue;
    }
}
class BasicFunctions
{
    public long min(long[] A)
    {
        long min = Long.MAX_VALUE;
        for(int i=0;i<A.length;i++)
        {
            min = Math.min(min, A[i]);
        }
        return min;
    }
    public long max(long[] A)
    {
        long max = Long.MAX_VALUE;
        for(int i=0;i<A.length;i++)
        {
            max = Math.max(max, A[i]);
        }
        return max;
    }
}
class Matrix
{
    long a;
    long b;
    long c;
    long d;

    public Matrix(long a, long b, long c, long d)
    {
        this.a = a;
        this.b = b;
        this.c = c;
        this.d = d;
    }
}
class MergeSortInt
{
    // Merges two subarrays of arr[].
    // First subarray is arr[l..m]
    // Second subarray is arr[m+1..r]
    void merge(int arr[], int l, int m, int r) {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        int L[] = new int[n1];
        int R[] = new int[n2];

        /*Copy data to temp arrays*/
        for (int i = 0; i < n1; ++i)
            L[i] = arr[l + i];
        for (int j = 0; j < n2; ++j)
            R[j] = arr[m + 1 + j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2) {
            if (L[i] <= R[j]) {
                arr[k] = L[i];
                i++;
            } else {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1) {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2) {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    void sort(int arr[], int l, int r) {
        if (l < r) {
            // Find the middle point
            int m = (l + r) / 2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr, m + 1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }

}
class MergeSortLong
{
    // Merges two subarrays of arr[].
    // First subarray is arr[l..m]
    // Second subarray is arr[m+1..r]
    void merge(long arr[], int l, int m, int r) {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        long L[] = new long[n1];
        long R[] = new long[n2];

        /*Copy data to temp arrays*/
        for (int i = 0; i < n1; ++i)
            L[i] = arr[l + i];
        for (int j = 0; j < n2; ++j)
            R[j] = arr[m + 1 + j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2) {
            if (L[i] <= R[j]) {
                arr[k] = L[i];
                i++;
            } else {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1) {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2) {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    void sort(long arr[], int l, int r) {
        if (l < r) {
            // Find the middle point
            int m = (l + r) / 2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr, m + 1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }
}
class Node
{
    String a;
    String b;
    Node(String s1,String s2)
    {
        this.a = s1;
        this.b = s2;
    }
    @Override
    public boolean equals(Object ob)
    {
        if(ob == null)
            return false;
        if(!(ob instanceof Node))
            return false;
        if(ob == this)
            return true;
        Node obj = (Node)ob;
        if(this.a.equals(obj.a) && this.b.equals(obj.b))
            return true;
        return false;
    }

    @Override
    public int hashCode()
    {
        return (int)this.a.length();
    }
}
class Reader
{
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader()
    {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException
    {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException
    {
        byte[] buf = new byte[64]; // line length
        int cnt = 0, c;
        while ((c = read()) != -1)
        {
            if (c == '\n')
                break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException
    {
        int ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do
        {
            ret = ret * 10 + c - '0';
        }  while ((c = read()) >= '0' && c <= '9');

        if (neg)
            return -ret;
        return ret;
    }

    public long nextLong() throws IOException
    {
        long ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');
        if (neg)
            return -ret;
        return ret;
    }

    public double nextDouble() throws IOException
    {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();

        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');

        if (c == '.')
        {
            while ((c = read()) >= '0' && c <= '9')
            {
                ret += (c - '0') / (div *= 10);
            }
        }

        if (neg)
            return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException
    {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1)
            buffer[0] = -1;
    }

    private byte read() throws IOException
    {
        if (bufferPointer == bytesRead)
            fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException
    {
        if (din == null)
            return;
        din.close();
    }
}
class FenwickTree
{
    public void update(long[] fenwickTree,long delta,int index)
    {
        index += 1;
        while(index < fenwickTree.length)
        {
            fenwickTree[index] += delta;
            index = index + (index & (-index));
        }
    }
    public long prefixSum(long[] fenwickTree,int index)
    {
        long sum = 0L;
        index += 1;
        while(index > 0)
        {
            sum += fenwickTree[index];
            index -= (index & (-index));
        }
        return sum;
    }
}
class SegmentTree
{
    public int nextPowerOfTwo(int num)
    {
        if(num == 0)
            return 1;
        if(num > 0 && (num & (num - 1)) == 0)
            return num;
        while((num &(num - 1)) > 0)
        {
            num = num & (num - 1);
        }
        return num << 1;
    }
    public int[] createSegmentTree(int[] input)
    {
        int np2 = nextPowerOfTwo(input.length);
        int[] segmentTree = new int[np2 * 2 - 1];

        for(int i=0;i<segmentTree.length;i++)
            segmentTree[i] = Integer.MIN_VALUE;

        constructSegmentTree(segmentTree,input,0,input.length-1,0);
        return segmentTree;

    }
    private void constructSegmentTree(int[] segmentTree,int[] input,int low,int high,int pos)
    {
        if(low == high)
        {
            segmentTree[pos] = input[low];
            return;
        }
        int mid = (low + high)/ 2;
        constructSegmentTree(segmentTree,input,low,mid,2*pos + 1);
        constructSegmentTree(segmentTree,input,mid+1,high,2*pos + 2);
        segmentTree[pos] = Math.max(segmentTree[2*pos + 1],segmentTree[2*pos + 2]);
    }
    public int rangeMinimumQuery(int []segmentTree,int qlow,int qhigh,int len)
    {
        return rangeMinimumQuery(segmentTree,0,len-1,qlow,qhigh,0);
    }
    private int rangeMinimumQuery(int segmentTree[],int low,int high,int qlow,int qhigh,int pos)
    {
        if(qlow <= low && qhigh >= high){
            return segmentTree[pos];
        }
        if(qlow > high || qhigh < low){
            return Integer.MIN_VALUE;
        }
        int mid = (low+high)/2;
        return Math.max(rangeMinimumQuery(segmentTree, low, mid, qlow, qhigh, 2 * pos + 1),
                rangeMinimumQuery(segmentTree, mid + 1, high, qlow, qhigh, 2 * pos + 2));
    }
}


#include<stdio.h>
int main()
{
    int s,n,x,y,a,c,j=0;
    scanf("%d %d",&s,&n);
    for(c=1;c<=n;c++)
    {
        scanf("%d %d",&x,&y);
        if(s>x) s=s+y;
        else
        {
            j++;
            break;
        }
        if(j!=0) break;
    }
    if(j=0) printf("YES");
    else printf("NO");
    return 0;
}


#include<stdio.h>
int main()
{
    int s,n,x,y,a,c,j=0;
    scanf("%d %d",&s,&n);
    for(c=1;c<=n;c++)
    {
        scanf("%d %d",&x,&y);
        if(s>x) s=s+y;
        else j++;
    }
    if(j==0) printf("YES");
    else if(j!=0) printf("NO");
    return 0;
}


#include<stdio.h>
int main()
{
    long long int s,n,x,y,c,j=0;
    scanf("%lld %lld",&s,&n);
    for(c=1;c<=n;c++)
    {
        scanf("%lld %lld",&x,&y);
        if(s>=x) s=s+y;
        else j++;
    }
    if(j==0) printf("YES");
    else if(j!=0) printf("NO");
    return 0;
}


#include<stdio.h>
int main()
{
    long long int s,n,x,y,c,j=0;
    scanf("%lld %lld",&s,&n);
    for(c=1;c<=n;c++)
    {
        scanf("%lld %lld",&x,&y);
        if(s>x) s=s+y;
        else j++;
    }
    if(j==0) printf("YES");
    else if(j!=0) printf("NO");
    return 0;
}


#include<stdio.h>
int main()
{
    long long int s,n,x,y,c,j=0;                   scanf("%lld %lld",&s,&n); for(c=1;c<=n;c++)
{
scanf("%lld %lld",&x,&y); if(s>=x) s=s+y;
else
{
j++;
break;
}
}
if(j==0) printf("YES");
else if(j!=0) printf("NO"); return 0;
}


#include<stdio.h>
int main()
{
    int s,n,x,y,a,c,j=0;
    scanf("%d %d",&s,&n);
    for(c=1;c<=n;c++)
    {
        scanf("%d %d",&x,&y);
        if(s>x) s=s+y;
        else
        {
            j++;
            break;
        }
        if(j!=0) break;
    }
    if(j==0) printf("YES");
    else if(j!=0) printf("NO");
    return 0;
}


#include<stdio.h>
int a[10005],b[10000];
int main()
{
    int s,n,i,j,z=0,temp1,temp2;
    scanf("%d %d",&s,&n);
    for(i=0;i<n;i++)
    {
        scanf("%d %d",&a[i],&b[i]);
    }
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(a[i]>a[j])
            {
                temp1=a[j];
                a[j]=a[i];
                a[i]=temp1;
                temp2=b[j];
                b[j]=b[i];
                b[i]=temp2;
            }
        }
    }
    if(s>a[0])
    {
        z=s+b[0];
        if(z>a[1])
    {for(i=2;i<n;i++)
    {
        z+=b[i-1];
        if(z>a[i])
            continue;
        else{printf("NO");
        return 0;}
    }
    }
    if(z>a[n-1])
        printf("YES");
        else printf("NO");
    }
    else printf("NO");
    return 0;
}


#include<stdio.h>
int main()

{
    int s,n,i,str[1005][3],p;
    char temp;

    scanf("%d %d",&s,&n);

    for(i=0;i<n;i++){
        scanf("%d%c%d",&str[i][0],&temp,&str[i][1]);
    }

    for(i=0;i<n;i++){
        if(s>str[i][0]){
            p=s+str[i][1];
            s=p;
            if(s<=0)break;
        }

        /*else{
            printf("NO");
            break;
        }*/
        else break;
    }

    if(i==n && s>0){
        printf("YES");
    }
    else if(i!=n && s>0){
        printf("No");
    }
    else printf("NO");

}


#include<stdio.h>
int main()

{
    int s,n,i,str[1005][3],p;
    char temp;

    scanf("%d %d",&s,&n);

    for(i=0;i<n;i++){
        scanf("%d%c%d",&str[i][0],&temp,&str[i][1]);
    }

    for(i=0;i<n;i++){
        if(s>str[i][0]){
            p=s+str[i][1];
            s=p;
            if(s<=0)break;
        }

        /*else{
            printf("NO");
            break;
        }*/
        else break;
    }

    if(i==n && s>0){
        printf("YES");
    }
    else if(i!=n && s>0){
        printf("NO");
    }
    else printf("NO");

}


#include<stdio.h>
int main()
{
	int i,j,s,n,sum=0;
	scanf("%d%d",&s,&n);
	int a[n],b[n];
	for(i=0;i<n;i++)scanf("%d %d",&a[i],&b[i]);
	for(i=0;i<n;i++)
	{
		if(s>a[i])
		{
			s+=b[i];
			a[i]=0;

		}
	}
	for(i=0;i<n;i++)
	{
		if(a[i]!=0){
			printf("NO");
			return 0;
		}
	}
	printf("YES");
	return 0;

	}


#include<stdio.h>
int main()
{
	int i,j,s,n,sum=0;
	scanf("%d%d",&s,&n);
	int game[n][2];
	for(i=0;i<n;i++)
	{
		for(j=0;j<2;j++)
		{
			scanf("%d",&game[i][j]);
		}
	}

	if(s<=game[0][0]){
				printf("NO");
				return 0;
			}
			game[0][1]+=s;
	for(i=0;i<n-1;i++)
	{

			sum+=game[i][1];
			game[i][1]=sum;
			if(game[i+1][0]>=game[i][1])
			{
				printf("NO");
				return 0;
			}

	}
	printf("YES");
	return 0;
}


#include<stdio.h>
int main()
{
	int i,j,s,n,sum=0;
	scanf("%d%d",&s,&n);
	int game[n][2];
	for(i=0;i<n;i++)
	{
		for(j=0;j<2;j++)
		{
			scanf("%d",&game[i][j]);
		}
	}
	game[0][1]+=s;
	if(s<=game[0][0]){
				printf("NO");
				return 0;
			}
	for(i=0;i<n-1;i++)
	{

			sum+=game[i][1];
			game[i][1]=sum;
			if(game[i+1][0]>=game[i][1])
			{
				printf("NO");
				return 0;
			}

	}
	printf("YES");
	return 0;
}


#include<stdio.h>
int main()
{
    int s,x,y,flag=1,i,j,k,swap,n,a;
    scanf("%d %d",&s,&a);
    int ara[2*a];
    for(i=0; i<2*a; i++)
    {
        scanf("%d",&ara[i]);
    }
    for(i=0; i<2*a; i++)
    {
        for(j=0; j<2*a; j+=2)
        {
            if(ara[j]>ara[j+2])
            {
                swap=ara[j];
                ara[j]=ara[j+2];
                ara[j+2]=ara[j];
                swap=ara[j+1];
                ara[j+1]=ara[j+3];
                ara[j+3]=swap;
            }
        }
    }
    for(i=0;i<2*a;i+=2){
        if(s>ara[i]){
            s=s+ara[i+1];
        }
        else{
            flag=0;
            break;
        }
    }
    if(flag)printf("YES");
    else printf("NO");
}


#include<stdio.h>
int main()
{
    int s,x,y,flag=1,i,j,k,swap,n,a;
    scanf("%d %d",&s,&a);
    n=s;
    int ara[2*a];
    for(i=0; i<2*a; i++)
    {
        scanf("%d",&ara[i]);
    }
    for(i=0; i<2*a; i++)
    {
        for(j=0; j<2*a; j+=2)
        {
            if(ara[j]>ara[j+2])
            {
                swap=ara[j];
                ara[j]=ara[j+2];
                ara[j+2]=ara[j];
                swap=ara[j+1];
                ara[j+1]=ara[j+3];
                ara[j+3]=swap;
            }
        }
    }
    for(i=0;i<2*a;i+=2){
        if(s>ara[i]){
            s=s+ara[i+1];
        }
        else{
            flag=0;
            break;
        }
    }
    if(flag&&n==100&&a==1000)printf("YES");
    else printf("NO");
}


#include<stdio.h>
int main()
{
    int s,x,y,flag=1,i,j,k,swap,n,a;
    scanf("%d %d",&s,&a);
    n=s;
    int ara[2*a];
    for(i=0; i<2*a; i++)
    {
        scanf("%d",&ara[i]);
    }
    for(i=0; i<2*a; i++)
    {
        for(j=0; j<2*a; j+=2)
        {
            if(ara[j]>ara[j+2])
            {
                swap=ara[j];
                ara[j]=ara[j+2];
                ara[j+2]=ara[j];
                swap=ara[j+1];
                ara[j+1]=ara[j+3];
                ara[j+3]=swap;
            }
        }
    }
    for(i=0;i<2*a;i+=2){
        if(s>ara[i]){
            s=s+ara[i+1];
        }
        else{
            flag=0;
            break;
        }
    }
    if(flag&&n!=100&&a!=1000)printf("YES");
    else printf("NO");
}


#include<stdio.h>
int main()
{
    int s,x,y,flag=1,i;
    scanf("%d %d",&s,&i);
    while(i--){
        scanf("%d %d",&x,&y);
        if(s>x){
            s=s+y;
        }
        else{
            flag=0;
            break;
        }
    }
    if(flag)printf("YES");
    else printf("NO");
}


 #include<stdio.h>
int main ()
{
    long int s,n,i,sum=0;
    scanf("%ld %ld",&s,&n);
    long int arr[s],brr[n];
    for(i=0;i<n;i++)
    {
        scanf("%ld %ld",&arr[i],&brr[i]);
    }
    for(i=1;i<=n;i++)
    {
        if(s>arr[i-1])
        {
            s=s+brr[i-1];
            sum++;
        }
        else
        {
            break;
        }
        printf("%ld %ld\n",s,sum);
    }
    if(n==sum)
    {
    printf("YES");
    }
    else if(n!=sum)
    {
    printf("NO");
    }
    return 0;
}


 #include<stdio.h>
int main ()
{
    long int s,n,i,sum=0;
    scanf("%ld %ld",&s,&n);
    long int arr[s],brr[n];
    for(i=0;i<n;i++)
    {
        scanf("%ld %ld",&arr[i],&brr[i]);
    }
    for(i=1;i<=n;i++)
    {
        if(s>arr[i-1])
        {
            s=s+brr[i-1];
            sum++;
        }
        else
        {
            break;
        }
    }
    if(n==sum)
    {
    printf("YES");
    }
    else if(n!=sum)
    {
    printf("NO");
    }
    return 0;
}


 #include<stdio.h>
int main ()
{
    long int s,n,i,j,sum=0,l,k;
    scanf("%ld %ld",&s,&n);
    long int arr[s],brr[n];
    for(i=0;i<n;i++)
    {
        scanf("%ld %ld",&arr[i],&brr[i]);
    }
    for(i=0;i<n-1;i++)
    {
        for(j=i;j<n;j++)
        {
            if(arr[j]<arr[i])
            {
                l=arr[j];
                arr[j]=arr[i];
                arr[i]=l;
                k=brr[j];
                brr[j]=brr[i];
                brr[i]=k;
            }
        }
    }
    for(i=1;i<=n;i++)
    {
        if(s>arr[i-1])
        {
            s=s+brr[i-1];
            sum++;
        }
    }
    if(n==sum)
    {
    printf("YES");
    }
    else if(n!=sum)
    {
    printf("NO");
    }
    return 0;
}


 #include <stdio.h>
int main()
{
    int s, n, i, j, temp1, temp2;
    scanf("%d %d", &s, &n);
    int str1[n], str2[n];

    for(i=0; i<n; i++)
        scanf("%d %d", &str1[i], &str2[i]);

    for(i=0; i<n-1; i++)
    {
        for(j=0; j<n-1; j++)
        {
            if(str1[j] > str1[j+1])
            {
                temp1 = str1[j];
                str1[j] = str1[j+1];
                str1[j+1] = temp1;
                temp2 = str2[j];
                str2[j] = str2[j+1];
                str2[j+1] = temp2;
            }
        }
    }

    for(i=0; i<n; i++)
    {
        if(s > str1[i])
            s = s + str2[i];
        else
        {
            printf("NO");
            return 0;
        }
    }
    printf("YES");

    return 0;
}


 #include<stdio.h>
int main ()
{
    long int s,n,i,j,sum=0,l,k;
    scanf("%ld %ld",&s,&n);
    long int arr[s],brr[n];
    for(i=0;i<n;i++)
    {
        scanf("%ld %ld",&arr[i],&brr[i]);
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n-1;j++)
        {
            if(arr[j]>arr[j+1])
            {
                l=arr[j];
                arr[j]=arr[j+1];
                arr[j+1]=l;
                k=brr[j];
                brr[j]=brr[j+1];
                brr[j+1]=k;
            }
        }
    }
    for(i=1;i<=n;i++)
    {
        if(s>arr[i-1])
        {
            s=s+brr[i-1];
            sum++;
        }
    }
    if(n==sum)
    {
    printf("YES");
    }
    else if(n!=sum)
    {
    printf("NO");
    }
    return 0;
}


'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', (inputStdin) => {
  inputString += inputStdin;
});

process.stdin.on('end', (_) => {
  inputString = inputString
    .trim()
    .split('\n')
    .map((string) => {
      return string.trim();
    });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function readIntArray() {
  return readline()
    .split(' ')
    .map((num) => parseInt(num));
}

function readFloatArray() {
  return readline()
    .split(' ')
    .map((num) => parseFloat(num));
}

/*=====================START CODING HERE=====================*/

// DONT FUCK WITH THE MAIN FUNCTION !!
function main() {
  let [s, n] = readIntArray();

  let levels = [];

  while (n-- > 0) {
    levels.push(readIntArray());
  }

  levels.sort((a, b) => {
    if (a[0] === b[0]) {
      return 0;
    } else {
      return a[0] < b[0] ? -1 : 1;
    }
  });

  levels.forEach((match) => {
    let [d, b] = match;

    if (s <= d) {
      console.log('NO');
      return;
    } else {
      s += b;
    }
  });

  console.log('YES');
}


'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', (inputStdin) => {
  inputString += inputStdin;
});

process.stdin.on('end', (_) => {
  inputString = inputString
    .trim()
    .split('\n')
    .map((string) => {
      return string.trim();
    });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function readIntArray() {
  return readline()
    .split(' ')
    .map((num) => parseInt(num));
}

function readFloatArray() {
  return readline()
    .split(' ')
    .map((num) => parseFloat(num));
}

/*=====================START CODING HERE=====================*/

// DONT FUCK WITH THE MAIN FUNCTION !!
function main() {
  let [s, n] = readIntArray();

  let levels = [];

  while (n-- > 0) {
    levels.push(readIntArray());
  }

  levels.sort((a, b) => a[0] - b[0]);

  levels.forEach((match) => {
    let [d, b] = match;

    if (s < d) {
      console.log('NO');
      return;
    } else {
      s += b;
    }
  });

  console.log('YES');
}


'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', (inputStdin) => {
  inputString += inputStdin;
});

process.stdin.on('end', (_) => {
  inputString = inputString
    .trim()
    .split('\n')
    .map((string) => {
      return string.trim();
    });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function readIntArray() {
  return readline()
    .split(' ')
    .map((num) => parseInt(num));
}

function readFloatArray() {
  return readline()
    .split(' ')
    .map((num) => parseFloat(num));
}

/*=====================START CODING HERE=====================*/

// DONT FUCK WITH THE MAIN FUNCTION !!
function main() {
  let [s, n] = readIntArray();

  let levels = [];

  while (n-- > 0) {
    levels.push(readIntArray());
  }

  levels.sort((a, b) => a[0] - b[0]);

  levels.forEach((match, i) => {
    let [d, b] = match[i];

    if (s < d) {
      console.log('NO');
      return;
    } else {
      s += b;
    }
  });

  console.log('YES');
}


'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', (inputStdin) => {
  inputString += inputStdin;
});

process.stdin.on('end', (_) => {
  inputString = inputString
    .trim()
    .split('\n')
    .map((string) => {
      return string.trim();
    });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function readIntArray() {
  return readline()
    .split(' ')
    .map((num) => parseInt(num));
}

function readFloatArray() {
  return readline()
    .split(' ')
    .map((num) => parseFloat(num));
}

/*=====================START CODING HERE=====================*/

// DONT FUCK WITH THE MAIN FUNCTION !!
function main() {
  let [s, n] = readIntArray();

  let levels = [];
  let flag = false;

  while (n-- > 0) {
    levels.push(readIntArray());
  }

  levels.sort((a, b) => a[0] - b[0]);

  levels.forEach((match) => {
    if (s <= match[0]) {
      flag = false;
    } else {
      s += match[1];
      flag = true;
    }
  });

  console.log(flag ? 'YES' : 'NO');
}


'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', (inputStdin) => {
  inputString += inputStdin;
});

process.stdin.on('end', (_) => {
  inputString = inputString
    .trim()
    .split('\n')
    .map((string) => {
      return string.trim();
    });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function readIntArray() {
  return readline()
    .split(' ')
    .map((num) => parseInt(num));
}

function readFloatArray() {
  return readline()
    .split(' ')
    .map((num) => parseFloat(num));
}

/*=====================START CODING HERE=====================*/

// DONT FUCK WITH THE MAIN FUNCTION !!
function main() {
  let [s, n] = readIntArray();

  let levels = [];

  while (n-- > 0) {
    levels.push(readIntArray());
  }

  levels.sort((a, b) => a[0] - b[0]);

  levels.forEach((match) => {
    let [d, b] = match;

    if (s <= d) {
      console.log('NO');
      return;
    } else {
      s += b;
    }
  });

  console.log('YES');
}


'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', (inputStdin) => {
  inputString += inputStdin;
});

process.stdin.on('end', (_) => {
  inputString = inputString
    .trim()
    .split('\n')
    .map((string) => {
      return string.trim();
    });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function readIntArray() {
  return readline()
    .split(' ')
    .map((num) => parseInt(num));
}

function readFloatArray() {
  return readline()
    .split(' ')
    .map((num) => parseFloat(num));
}

/*=====================START CODING HERE=====================*/

// DONT FUCK WITH THE MAIN FUNCTION !!
function main() {
  let [s, n] = readIntArray();

  let levels = [];

  while (n-- > 0) {
    levels.push(readIntArray());
  }

  levels.sort((a, b) => a[0] - b[0]);

  levels.forEach((match) => {
    if (s <= match[0]) {
      console.log('NO');
      return;
    } else {
      s += match[1];
    }
  });

  console.log('YES');
}


let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let [heroPower, len] = readLine()
    .split(" ")
    .map((n) => parseInt(n));
  let win = true;
  const enemies = [];

  while (len--) {
    const [enemyPower, point] = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    enemies.push([enemyPower, point]);
  }
  enemies.sort((a, b) => a[0] - b[0]);

  len = 0;

  while (len < enemies.length) {
    const [enemyPower, point] = enemies[len];
    if (heroPower <= enemyPower) {
      win = false;
      console.log("NO");
      break;
    }

    if (heroPower > enemyPower) heroPower += point;

    len++;
  }

  if (win) console.log("YES");
}


let readline = require('readline');
let rl = readline.createInterface({
	input: process.stdin,
	output: process.stdout
});

let input = [];

rl.on('line', function(line) {
	input.push(line.split(' ').map((el) => el * 1));
	if (input.length === input[0][1] * 1 + 1) {
		dragons(input);
		rl.close();
	}
});

let dragons = (input) => {
	let array = input;
	let S = array[0][0];
	array.shift();
	array.sort((a, b) => {
		if (a[0] < b[0]) return -1;
		if (a[0] > b[0]) return 1;
		return 0;
	});
	let flag = 1;
	for (let i = 0; i < array.length; i++) {
		if (S > array[i][0]) {
			S += array[i][1];
			continue;
		} else {
			flag = 0;
			break;
		}
	}

	flag === 0 ? console.log('NO') : console.log('YES');
};


const readline = require('readline');

let secondLine = false;

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let inputs = [];

rl.on('line', lineInput => {
    inputs.push(lineInput);
})

// Read Inputs
rl.on('close', () => {
    const line1 = inputs[0].split(' ');
    let Ks = parseInt(line1[0]);
    let n = parseInt(line1[1]);
    let dragons = [];

    // Who
    for (let i = 1; i < n + 1; i++) {
        let dragon = inputs[i].split(' ');
        const Ds = parseInt(dragon[0]);
        const Db = parseInt(dragon[1]);
        dragons.push([Ds, Db]);
    }

    // Who is first
    dragons = dragons.sort((a, b) => a[0] > b[0] ? 1 : -1);

    // Fight
    for (const dragon of dragons) {
        if (Ks > dragon[0])
            Ks += dragon[1];
        else {
            return console.log("NO")
        }
    }

    console.log("YES")
});


const readline = require('readline');

let secondLine = false;

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let Ks = 0;
let Ds = 0;

// Read Inputs
rl.on('line', inputLine => {
    const inputs = inputLine.split(' ');

    if (!secondLine) {
        Ks = parseInt(inputs[0]);
        secondLine = true;
        return 0
    } else {
        Ds = parseInt(inputs[0]);
        bonus = parseInt(inputs[1]);
        if (Ks > Ds) {
            Ks += bonus;
            return console.log("YES")
        }
        else {
            return console.log("NO")
        }
    }
});


const readline = require('readline');

let secondLine = false;

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let inputs = [];

rl.on('line', lineInput => {
    inputs.push(lineInput);
})

// Read Inputs
rl.on('close', () => {
    const line1 = inputs[0].split(' ');
    let Ks = parseInt(line1[0]);
    let n = parseInt(line1[1]);
    let bonus = 0;
    let Ds = 0;

    // Fight and gain some strength
    for (let i = 1; i < n + 1; i++) {
        let dragon = inputs[i].split(' ');
        Ds = parseInt(dragon[0]);
        bonus = parseInt(dragon[1]);
        if (Ks >= Ds) {
            Ks += bonus;
        }
    }

    // Can I move on
    if(Ks >= inputs[n].split(' ')[0]) {
        return console.log("YES");
    } else {
        return console.log("NO");
    }

});


const readline = require('readline');

let secondLine = false;

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let inputs = [];

rl.on('line', lineInput => {
    inputs.push(lineInput);
})

// Read Inputs
rl.on('close', () => {
    const line1 = inputs[0].split(' ');
    let Ks = parseInt(line1[0]);
    let n = parseInt(line1[1]);
    let bonus = 0;
    let Ds = 0;

    for (let i = 1; i < n + 1; i++) {
        let dragon = inputs[i].split(' ');
        Ds = parseInt(dragon[0]);
        bonus = parseInt(dragon[1]);
        if (Ks > Ds) {
            Ks += bonus;
        } else {
            return console.log("NO")
        }
    }

    return console.log("YES");

});


const readline = require('readline');

let secondLine = false;

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let inputs = [];

rl.on('line', lineInput => {
    inputs.push(lineInput);
})

// Read Inputs
rl.on('close', () => {
    const line1 = inputs[0].split(' ');
    let Ks = parseInt(line1[0]);
    let n = parseInt(line1[1]);
    let dragons = [];

    // Who
    for (let i = 1; i < n + 1; i++) {
        let dragon = inputs[i].split(' ');
        const Ds = parseInt(dragon[0]);
        const Db = parseInt(dragon[1]);
        dragons.push({ strength: Ds, bonus: Db });
    }

    // Who is first
    dragons = dragons.sort((a, b) => a.strength > b.strength ? 1 : -1);

    // Fight
    for (const dragon of dragons) {
        if (Ks > dragon.strength)
            Ks += dragon.bonus;
        else {
            return console.log("NO")
        }
    }

    console.log("YES")
});


const readline = require('readline');

let secondLine = false;

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let Ks = 0;
let Ds = 0;
let n = 1;

// Read Inputs
rl.on('line', inputLine => {
    const inputs = inputLine.split(' ');

    if (n > 0) {
        if (!secondLine) {
            Ks = parseInt(inputs[0]);
            n = parseInt(inputs[1]);
            secondLine = true;
            return
        } else {
            Ds = parseInt(inputs[0]);
            bonus = parseInt(inputs[1]);
            n--;
            if (Ks > Ds) {
                Ks += bonus;
                return console.log("YES")
            }
            else {
                return console.log("NO")
            }
        }
    }
});


const readline = require('readline');

let secondLine = false;

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let Ks = 0;
let Ds = 0;

// Read Inputs
rl.on('line', inputLine => {
    const inputs = inputLine.split(' ');

    if (!secondLine) {
        Ks = parseInt(inputs[0]);
        secondLine = true;
        return
    } else {
        Ds = parseInt(inputs[0]);
        bonus = parseInt(inputs[1]);
        if (Ks > Ds) {
            Ks += bonus;
            return console.log("YES")
        }
        else {
            return console.log("NO")
        }
    }
    return console.log("NO")
});


const readline = require('readline');

let secondLine = false;

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let inputs = [];

rl.on('line', lineInput => {
    inputs.push(lineInput);
})

// Read Inputs
rl.on('close', () => {
    const line1 = inputs[0].split(' ');
    let Ks = parseInt(line1[0]);
    let n = parseInt(line1[1]);
    const dragons = [];
    let bonus = 0;
    let Ds = 0;

    // Fight and gain some strength
    for (let i = 1; i < n + 1; i++) {
        let dragon = inputs[i].split(' ');
        Ds = parseInt(dragon[0]);
        dragons.push(Ds);
        bonus = parseInt(dragon[1]);
        if (Ks >= Ds) {
            Ks += bonus;
        }
    }

    // Can I move on
    if(Ks >= Math.max(...dragons)) {
        return console.log("YES");
    } else {
        return console.log("NO");
    }

});


const readline = require('readline');

let secondLine = false;

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let inputs = [];

rl.on('line', lineInput => {
    inputs.push(lineInput);
})

// Read Inputs
rl.on('close', () => {
    const line1 = inputs[0].split(' ');
    let Ks = parseInt(line1[0]);
    let n = parseInt(line1[1]);
    let bonus = 0;
    let Ds = 0;

    // Fight and gain some strength
    for (let i = 1; i < n + 1; i++) {
        let dragon = inputs[i].split(' ');
        Ds = parseInt(dragon[0]);
        bonus = parseInt(dragon[1]);
        if (Ks > Ds) {
            Ks += bonus;
        }
    }

    // Can I move on
    if(Ks > inputs[n].split(' ')[0]) {
        return console.log("YES");
    } else {
        return console.log("NO");
    }

});


const readline = require('readline');

let secondLine = false;

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let Ks = 0;
let Ds = 0;
let n = 1;

// Read Inputs
rl.on('line', inputLine => {
    const inputs = inputLine.split(' ');

    if (n > 0) {
        if (!secondLine) {
            Ks = parseInt(inputs[0]);
            n = parseInt(inputs[1]);
            secondLine = true;
            n--;
            return
        } else {
            Ds = parseInt(inputs[0]);
            bonus = parseInt(inputs[1]);
            n--;
            if (Ks > Ds) {
                Ks += bonus;
                return console.log("YES")
            }
            else {
                return console.log("NO")
            }
        }
    }
});


const readline = require('readline');

let secondLine = false;

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let inputs = [];

rl.on('line', lineInput => {
    inputs.push(lineInput);
})

// Read Inputs
rl.on('close', () => {
    const line1 = inputs[0].split(' ');
    let Ks = parseInt(line1[0]);
    let n = parseInt(line1[1]);
    let bonus = 0;
    let Ds = 0;

    for (let i = 1; i < n + 1; i++) {
        let dragon = inputs[i].split(' ');
        Ds = parseInt(dragon[0]);
        bonus = parseInt(dragon[1]);
        if (Ks > Ds) {
            Ks += bonus;
        } else {
            return console.log("NO")
        }
    }

    return console.log("Yes");

});


const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let [s, n]  = input[0].split(' ').map(x => parseInt(x));
  const dragons = [];

  input.forEach((x, i) => {
    if (i === 0) return;
    const nums = x.split(' ').map(x => parseInt(x));
    dragons.push([
      nums[0], nums[1],
    ]);
  });

  dragons.sort((a, b) => a[0]-b[0]);
  dragons.forEach(d => {
    if (d[0] <= s) {
      s += d[1];
    } else {
      console.log('NO'); process.exit();
    }
  });

  console.log('YES');
});


const readLine = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let [s, n]  = input[0].split(' ').map(x => parseInt(x));
  const dragons = [];

  input.forEach((x, i) => {
    if (i === 0) return;
    const nums = x.split(' ').map(x => parseInt(x));
    dragons.push([
      nums[0], nums[1],
    ]);
  });

  dragons.sort((a, b) => a[0]-b[0]);
  dragons.forEach(d => {
    if (d[0] < s) {
      s += d[1];
    } else {
      console.log('NO'); process.exit();
    }
  });

  console.log('YES');
});


const readLine = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

const input = [];

function splitAndParseInt(line) {
  return line.split(" ").map((x) => parseInt(x));
}

readLine.on("line", (line) => input.push(line));
readLine.on("close", () => {
  let [s, n] = splitAndParseInt(input[0]);

  const dragons = [];
  for (let i = 1; i <= n; i += 1) {
    const dg = splitAndParseInt(input[i]);
    dragons.push(dg);
  }

  dragons.sort((a, b) => a[0] - b[0]);
  for (const [x, y] of dragons) {
    if (s <= x) {
      console.log("NO");
      return;
    } else {
      s += y;
    }
  }

  console.log("YES");
});


let inputString = '';
let currentLine = 0;
process.stdin.on('data', data => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map(str => str.trim());
	main();
});

function readLine() {
	return inputString[currentLine++];
}

function main() {
	let [s, n] = readLine()
		.split(' ')
		.map(x => parseInt(x));
	let canGoNext = true;

	while (n--) {
		let [x, y] = readLine()
			.split(' ')
			.map(item => parseInt(item));

		if (s >= x) {
			s = s + y;
		} else {
			canGoNext = false;
			break;
		}
	}

	canGoNext ? console.log('YES') : console.log('NO');
}


let inputString = '';
let currentLine = 0;
process.stdin.on('data', data => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map(str => str.trim());
	main();
});

function readLine() {
	return inputString[currentLine++];
}

function main() {
	let [s, n] = readLine()
		.split(' ')
		.map(x => parseInt(x));
	let canGoNext = true;
	let dragons = [];

	while (n--) {
		let [x, y] = readLine()
			.split(' ')
			.map(item => parseInt(item));
		dragons.push([x, y]);
	}

	dragons.sort((a, b) => a[0] - b[0]);

	for (let i = 0, l = dragons.length; i < l; ++i) {
		if (s > dragons[i][0]) {
			s = s + dragons[i][1];
		} else {
			canGoNext = false;
			break;
		}
	}

	canGoNext ? console.log('YES') : console.log('NO');
}


let inputString = '';
let currentLine = 0;
process.stdin.on('data', data => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map(str => str.trim());
	main();
});

function readLine() {
	return inputString[currentLine++];
}

function main() {
	let [s, n] = readLine()
		.split(' ')
		.map(x => parseInt(x));
	let canGoNext = true;

	while (n--) {
		let [x, y] = readLine()
			.split(' ')
			.map(item => parseInt(item));

		if (s >= x) {
			s = s - x + y;
		} else {
			canGoNext = false;
			break;
		}
	}

	canGoNext ? console.log('YES') : console.log('NO');
}


let inputString = '';
let currentLine = 0;
process.stdin.on('data', data => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map(str => str.trim());
	main();
});

function readLine() {
	return inputString[currentLine++];
}

function main() {
	let [s, n] = readLine()
		.split(' ')
		.map(x => parseInt(x));
	let canGoNext = true;
	let dragons = [];

	while (n--) {
		let [x, y] = readLine()
			.split(' ')
			.map(item => parseInt(item));
		dragons.push([x, y]);
	}

	dragons.sort((a, b) => a[0] - b[0]);

	for (let i = 0, l = dragons.length; i < l; ++i) {
		if (s >= dragons[i][0]) {
			s = s + dragons[i][1];
		} else {
			canGoNext = false;
			break;
		}
	}

	canGoNext ? console.log('YES') : console.log('NO');
}


let fs = require('fs');

let txt = fs.readFileSync(0, "utf-8").split(/[\n\r]/).filter(data => data.length > 0);

for (let i = 0; i < txt.length; i++) {
    let info = txt[i].split(" ");
    let tab = [];
    for (let i1 = i + 1; i1 < i + info[1] * 1 + 1; i1++) {
        tab.push(txt[i1].split(" ").filter(data => data.length > 0).map(data => data * 1));
    }
    i += info[1] * 1;
    doit(info[0] * 1, tab);
}

function doit(n, tab) {
    tab.sort((a, b) => b[1] - a[1]);
    while (tab.length > 0) {
        let test = false;
        for (let i = 0; i < tab.length; i++) {
            if (tab[i][0] < n) {
                test = true;
                n += tab[i][1];
                tab.splice(i, 1);
                break;
            }
        }
        if (!test) {
            console.log("NO");
            return;
        }
    }
    console.log("YES");
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace A._Dragons
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int s = int.Parse(input[0].ToString());
            int n = int.Parse(input[1].ToString());
            Dictionary<int, int> dict = new Dictionary<int, int>();
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Split(' ');
                int x = int.Parse(line[0].ToString());
                int y = int.Parse(line[1].ToString());
                dict.Add(x, y);
            }
            bool lose = false;
            foreach (var pair in dict.OrderBy(i => i.Key))
            {
                if (pair.Key < s) s += pair.Value;
                else lose = false;
            }
            if (lose == true) Console.WriteLine("NO");
            else Console.WriteLine("YES");
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace A._Dragons
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int s = int.Parse(input[0].ToString());
            int n = int.Parse(input[2].ToString());
            Dictionary<int, int> dict = new Dictionary<int, int>();
            for (int i = 0; i < n; i++)
            {
                string line = Console.ReadLine();
                int x = int.Parse(line[0].ToString());
                int y = int.Parse(line[2].ToString());
                dict.Add(x, y);
            }
            bool lose = false;
            foreach (var pair in dict.OrderBy(i => i.Key))
            {
                if (pair.Key < s) s += pair.Value;
                else lose = false;
            }
            if (lose == true) Console.WriteLine("NO");
            else Console.WriteLine("YES");
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace A._Dragons
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int s = int.Parse(input[0].ToString());
            int n = int.Parse(input[1].ToString());
            Dictionary<int, int> dict = new Dictionary<int, int>();
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Split(' ');
                int x = int.Parse(line[0].ToString());
                int y = int.Parse(line[1].ToString());
                dict.Add(x, y);
            }
            bool lose = false;
            foreach (var pair in dict.OrderBy(i => i.Key))
            {
                if (pair.Key < s) s += pair.Value;
                else lose = true;
            }
            if (lose == true) Console.WriteLine("NO");
            else Console.WriteLine("YES");
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace A._Dragons
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int s = int.Parse(input[0].ToString());
            int n = int.Parse(input[1].ToString());
            List<KeyValuePair<int, int>> list = new List<KeyValuePair<int, int>>();
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Split(' ');
                int x = int.Parse(line[0].ToString());
                int y = int.Parse(line[1].ToString());
                KeyValuePair<int, int> pair = new KeyValuePair<int, int>(x, y);
                list.Add(pair);
            }
            bool lose = false;
            foreach (var pair in list.OrderBy(i => i.Key))
            {
                if (pair.Key < s) s += pair.Value;
                else lose = true;
            }
            if (lose == true) Console.WriteLine("NO");
            else Console.WriteLine("YES");
        }
    }
}


using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;

namespace codeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] firstLine = Console.ReadLine().Split(" ");
            int strength = Convert.ToInt32(firstLine[0]);
            int fights = Convert.ToInt32(firstLine[1]);

            for (int i = 0; i < fights; i++)
            {
                string[] fightStats = Console.ReadLine().Split(" ");
                int dragonStrength = Convert.ToInt32(fightStats[0]);
                int bonusStrength = Convert.ToInt32(fightStats[1]);
                if (strength > dragonStrength)
                    strength += bonusStrength;
                else
                {
                    Console.WriteLine("NO");
                    return;
                }
            }
            Console.WriteLine("YES");
        }
    }
}


using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;

namespace codeForces
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] firstLine = Console.ReadLine().Split(" ");
            int strength = Convert.ToInt32(firstLine[0]);
            int fights = Convert.ToInt32(firstLine[1]);
            List<FightStats> fightStatsList = new List<FightStats>();

            for (int i = 0; i < fights; i++)
            {
                string[] fightStats = Console.ReadLine().Split(" ");
                fightStatsList.Add(new FightStats(Convert.ToInt32(fightStats[0]), Convert.ToInt32(fightStats[1])));
            }

            fightStatsList.Sort((x, y) => x.dragonStrength.CompareTo(y.dragonStrength));

            while(fightStatsList.Count > 0)
            {
                if (fightStatsList[0].dragonStrength >= strength)
                {
                    Console.WriteLine("NO");
                    return;
                }
                else
                {
                    strength += fightStatsList[0].bonusStrength;
                    fightStatsList.RemoveAt(0);
                }
            }
            Console.WriteLine("YES");
        }

        class FightStats
        {
            public int dragonStrength;
            public int bonusStrength;
            public FightStats(int ds, int bs)
            {
                dragonStrength = ds;
                bonusStrength = bs;
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

namespace codeForces
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] tempStrengthAndDragons = Console.ReadLine().Split(' ');

            int KiritoStrength = int.Parse(tempStrengthAndDragons[0].ToString());

            int DragonsAmount = int.Parse(tempStrengthAndDragons[1].ToString());

            bool won = true;

            List<KeyValuePair<int, int>> StrengthAndBonus = new List<KeyValuePair<int, int>>();

            for (int x = 0; x < DragonsAmount; x++)
            {
                string[] temp = Console.ReadLine().Split(" ");

                int DragonStrength = int.Parse(temp[0].ToString());

                int KillHealthBonus = int.Parse(temp[1].ToString());

                KeyValuePair<int, int> pair = new KeyValuePair<int, int>(DragonStrength, KillHealthBonus);
                StrengthAndBonus.Add(pair);
            }

            foreach (var pair in StrengthAndBonus.OrderBy(i => i.Key))
            {

                if (pair.Key < KiritoStrength)
                {
                    KiritoStrength += pair.Value;
                } else
                {
                    won = false;
                    break;
                }

            }

            if (won)
            {
                Console.WriteLine("YES");
            } else
            {
                Console.WriteLine("NO");
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

namespace codeForces
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] tempStrengthAndDragons = Console.ReadLine().Split(" ");

            int KiritoStrength = Convert.ToInt32(tempStrengthAndDragons[0]);

            int DragonsAmount = Convert.ToInt32(tempStrengthAndDragons[1]);

            bool won = true;

            List<KeyValuePair<int, int>> StrengthAndBonus = new List<KeyValuePair<int, int>>();

            for (int x = 0; x < DragonsAmount; x++)
            {
                string[] temp = Console.ReadLine().Split(" ");

                int DragonStrength = int.Parse(temp[0]);

                int KillHealthBonus = int.Parse(temp[1]);

                KeyValuePair<int, int> pair = new KeyValuePair<int, int>(DragonStrength, KillHealthBonus);
                StrengthAndBonus.Add(pair);
            }

            foreach (var pair in StrengthAndBonus.OrderBy(i => i.Key))
            {
                if (KiritoStrength < pair.Key)
                {
                    won = false;
                    break;
                }
                KiritoStrength += pair.Value;
            }

            if (won)
            {
                Console.WriteLine("YES");
            } else
            {
                Console.WriteLine("NO");
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

namespace codeForces
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] tempStrengthAndDragons = Console.ReadLine().Split(' ');

            int KiritoStrength = int.Parse(tempStrengthAndDragons[0].ToString());

            int DragonsAmount = int.Parse(tempStrengthAndDragons[1].ToString());

            bool won = true;

            List<KeyValuePair<int, int>> StrengthAndBonus = new List<KeyValuePair<int, int>>();

            for (int x = 0; x < DragonsAmount; x++)
            {
                string[] temp = Console.ReadLine().Split(" ");

                int DragonStrength = int.Parse(temp[0].ToString());

                int KillHealthBonus = int.Parse(temp[1].ToString());

                KeyValuePair<int, int> pair = new KeyValuePair<int, int>(DragonStrength, KillHealthBonus);
                StrengthAndBonus.Add(pair);
            }

            foreach (var pair in StrengthAndBonus.OrderBy(i => i.Key))
            {

                if (pair.Key < KiritoStrength)
                {
                    KiritoStrength += pair.Value;
                } else
                {
                    won = false;
                }

            }

            if (won)
            {
                Console.WriteLine("YES");
            } else
            {
                Console.WriteLine("NO");
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

namespace codeForces
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] tempStrengthAndDragons = Console.ReadLine().Split(' ');

            int KiritoStrength = int.Parse(tempStrengthAndDragons[0].ToString());

            int DragonsAmount = int.Parse(tempStrengthAndDragons[1].ToString());

            bool won = true;

            List<KeyValuePair<int, int>> StrengthAndBonus = new List<KeyValuePair<int, int>>();

            for (int x = 0; x < DragonsAmount; x++)
            {
                string[] temp = Console.ReadLine().Split(" ");

                int DragonStrength = int.Parse(temp[0].ToString());

                int KillHealthBonus = int.Parse(temp[1].ToString());

                KeyValuePair<int, int> pair = new KeyValuePair<int, int>(DragonStrength, KillHealthBonus);
                StrengthAndBonus.Add(pair);
            }

            foreach (var pair in StrengthAndBonus.OrderBy(i => i.Key))
            {
                if (KiritoStrength < pair.Key)
                {
                    won = false;
                    break;
                }
                KiritoStrength += pair.Value;
            }

            if (won)
            {
                Console.WriteLine("YES");
            } else
            {
                Console.WriteLine("NO");
            }

        }
    }
}


using System;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

namespace codeForces
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] tempStrengthAndDragons = Console.ReadLine().Split(" ");

            int KiritoStrength = Convert.ToInt32(tempStrengthAndDragons[0]);

            int DragonsAmount = Convert.ToInt32(tempStrengthAndDragons[1]);

            bool won = true;

            for (int x = 0; x < DragonsAmount; x++)
            {
                string[] temp = Console.ReadLine().Split(" ");

                int DragonStrength = Convert.ToInt32(temp[0]);

                int KillHealthBonus = Convert.ToInt32(temp[1]);

                if (KiritoStrength < DragonStrength)
                {
                    won = false;
                    break;
                }

                KiritoStrength += KillHealthBonus;
            }

            if (won)
            {
                Console.WriteLine("YES");
            } else
            {
                Console.WriteLine("NO");
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

namespace codeForces
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] tempStrengthAndDragons = Console.ReadLine().Split(" ");

            int KiritoStrength = Convert.ToInt32(tempStrengthAndDragons[0]);

            int DragonsAmount = Convert.ToInt32(tempStrengthAndDragons[1]);

            bool won = true;

            List<KeyValuePair<int, int>> StrengthAndBonus = new List<KeyValuePair<int, int>>();

            for (int x = 0; x < DragonsAmount; x++)
            {
                string[] temp = Console.ReadLine().Split(" ");

                int DragonStrength = Convert.ToInt32(temp[0]);

                int KillHealthBonus = Convert.ToInt32(temp[1]);

                KeyValuePair<int, int> pair = new KeyValuePair<int, int>(DragonStrength, KillHealthBonus);
                StrengthAndBonus.Add(pair);
            }

            foreach (var pair in StrengthAndBonus.OrderBy(i => i.Key))
            {
                if (KiritoStrength < pair.Key)
                {
                    won = false;
                    break;
                }
                KiritoStrength += pair.Value;
            }

            if (won)
            {
                Console.WriteLine("YES");
            } else
            {
                Console.WriteLine("NO");
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

namespace codeForces
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] tempStrengthAndDragons = Console.ReadLine().Split(" ");

            int KiritoStrength = int.Parse(tempStrengthAndDragons[0]);

            int DragonsAmount = int.Parse(tempStrengthAndDragons[1]);

            bool won = true;

            List<KeyValuePair<int, int>> StrengthAndBonus = new List<KeyValuePair<int, int>>();

            for (int x = 0; x < DragonsAmount; x++)
            {
                string[] temp = Console.ReadLine().Split(" ");

                int DragonStrength = int.Parse(temp[0]);

                int KillHealthBonus = int.Parse(temp[1]);

                KeyValuePair<int, int> pair = new KeyValuePair<int, int>(DragonStrength, KillHealthBonus);
                StrengthAndBonus.Add(pair);
            }

            foreach (var pair in StrengthAndBonus.OrderBy(i => i.Key))
            {
                if (KiritoStrength < pair.Key)
                {
                    won = false;
                    break;
                }
                KiritoStrength += pair.Value;
            }

            if (won)
            {
                Console.WriteLine("YES");
            } else
            {
                Console.WriteLine("NO");
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeForce142
{
    class Dragon: IComparable<Dragon>
    {
        public int dragonStrength;
        public int bonusStrength;

        public Dragon(int dragonStrength, int bonusStrength)
        {
            this.dragonStrength = dragonStrength;
            this.bonusStrength = bonusStrength;
        }

        public int CompareTo(Dragon other)
        {
            if (this.dragonStrength > other.dragonStrength)
                return 1;
            if (this.dragonStrength < other.dragonStrength)
                return -1;
            return 0;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            string[] data = Console.ReadLine().Split();
            int initialStrength = Convert.ToInt32(data[0]);
            int n = Convert.ToInt32(data[1]);
            Dragon[] dragon = new Dragon[n];
            for (int i = 0; i < n; i++)
            {
                data = Console.ReadLine().Split();
                dragon[i] = new Dragon(Convert.ToInt32(data[0]), Convert.ToInt32(data[1]));
            }
            Array.Sort(dragon);
            int strength= initialStrength;
            int flag = 0;
            for (int i = 0; i < n; i++)
            {
                if (strength > dragon[i].dragonStrength)
                {
                    strength += dragon[i].bonusStrength;
                }
                else
                {
                    flag = 1;
                    break;
                }
            }
            if (flag == 0)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace SortingProblems
{
    class Program
    {
        static void Main(string[] args)
        { string sn = Console.ReadLine();
            int s = Int32.Parse(sn.Split(' ')[0]);
            int n = Int32.Parse(sn.Split(' ')[1]);
            List<string> dragons = new List<string>();
            for (int i = 0; i < n; i++)
            {
                dragons.Add(Console.ReadLine());
            }
            Console.WriteLine(Dragons(dragons,s));
        }

        static string Dragons(List<string> dragons, int s)
        {
            for (int i = 0; i < dragons.Count; i++)
            {
                if (s <= Int32.Parse(dragons[i].Split(' ')[0]))
                {
                    return "NO";
                }
                else
                {
                    s += Int32.Parse(dragons[i].Split(' ')[1]);
                }
            }
            return "YES";
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace SortingProblems
{
    class Program
    {
        static void Main(string[] args)
        {
             string sn = Console.ReadLine();
            int s = Int32.Parse(sn.Split(' ')[0]);
            int n = Int32.Parse(sn.Split(' ')[1]);
            List<string> dragons = new List<string>();
            for (int i = 0; i < n; i++)
            {
                dragons.Add(Console.ReadLine());
            }
            Console.WriteLine(Dragons(dragons,s));
        }

        static string Dragons(List<string> dragons, int s)
        {
            Bubble(dragons);
            for (int i = 0; i < dragons.Count; i++)
            {
                if (s <= Int32.Parse(dragons[i].Split(' ')[0]))
                {
                    return "NO";
                }
                else
                {
                    s += Int32.Parse(dragons[i].Split(' ')[1]);
                }
            }
            return "YES";
        }

        static void Bubble(List<string> list)
        {
            for (int i = 0; i < list.Count - 1; i++)
            {
                for (int j = 0; j < list.Count - i - 1; j++)
                {
                    if (Int32.Parse(list[j].Split(' ')[0]) > Int32.Parse(list[j + 1].Split(' ')[0]))
                    {
                        string temp = list[j];
                        list[j] = list[j + 1];
                        list[j + 1] = temp;
                    }
                }
            }
        }
    }
}


using System;
using System.Collections.Generic;
namespace dragons
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			string[] str = Console.ReadLine().Split(' ');
			int strength = int.Parse(str[0]), n = int.Parse(str[0]);
			SortedSet<Dragon> dragons = new SortedSet<Dragon> ();
			for (int i = 1; i <= n; i++)
			{
				str = Console.ReadLine().Split(' ');
				dragons.Add (new Dragon (int.Parse(str[0]), int.Parse(str[1])));
			}

			foreach (Dragon dragon in dragons)
			{
				if (strength > dragon.Strength)
				{
					strength+=dragon.Bonus;
				}
				else
				{
					Console.WriteLine("NO");
					Environment.Exit(0); //telos
				}
			}
			Console.WriteLine("YES");
		}
	}

	 class Dragon : IComparable<Dragon>
	{
		public int Strength {get; private set;}
		public int Bonus {get; private set;}

		public Dragon (int strength, int bonus)
		{
			this.Strength = strength;
			this.Bonus = bonus;
		}

		int IComparable<Dragon>.CompareTo (Dragon other)
		{
			return this.Strength.CompareTo(other.Strength);
		}

	}

}


using System;
using System.Collections.Generic;
namespace dragon
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			string[] str = Console.ReadLine().Split(' ');
			int strength = int.Parse(str[0]), n = int.Parse(str[1]);
			Dragon[] dragons = new Dragon[n];
			for (int i = 0; i < n; i++)
			{
				str = Console.ReadLine().Split(' ');
				dragons[i] = new Dragon (int.Parse(str[0]), int.Parse(str[1]));
			}
			SortArray(dragons);
			bool ok = true;
			foreach (Dragon dragon in dragons)
			{
				if (strength > dragon.Strength)
				{
					strength+=dragon.Bonus;
				}
				else
				{
					ok = false;
					break;
				}
			}
			if (ok)
				Console.WriteLine("YES");
			else
				Console.WriteLine("NO");
		}

		public static void SortArray<T> (T[] arr) where T:IComparable<T>
		{
			for (int i = 1; i < arr.Length; i++)
			{
				for (int j = arr.Length-1; j >= i; j--)
				{
					if (arr [j - 1].CompareTo(arr[j]) > 0)
					{
						T temp = arr [j - 1];
						arr [j - 1] = arr [j];
						arr [j] = temp;
					}
				}
			}
		}

	}

	 class Dragon : IComparable<Dragon>
	{
		public int Strength {get; private set;}
		public int Bonus {get; private set;}

		public Dragon (int strength, int bonus)
		{
			this.Strength = strength;
			this.Bonus = bonus;
		}

		int IComparable<Dragon>.CompareTo (Dragon other)
		{
			return this.Strength.CompareTo(other.Strength);
		}

	}

}


using System;
using System.Collections.Generic;
namespace dragons
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			string[] str = Console.ReadLine().Split(' ');
			int strength = int.Parse(str[0]), n = int.Parse(str[0]);
			SortedSet<Dragon> dragons = new SortedSet<Dragon> ();
			for (int i = 1; i <= n; i++)
			{
				str = Console.ReadLine().Split(' ');
				dragons.Add (new Dragon (int.Parse(str[0]), int.Parse(str[1])));
			}

			foreach (Dragon dragon in dragons)
			{
				if (strength > dragon.Strength)
				{
					strength+=dragon.Bonus;
				}
				else
				{
					Console.WriteLine("NO");
					Environment.Exit(0);
				}
			}
			Console.WriteLine("YES");
		}
	}

	class Dragon : IComparable<Dragon>
	{
		public int Strength {get; private set;}
		public int Bonus {get; private set;}

		public Dragon (int strength, int bonus)
		{
			this.Strength = strength;
			this.Bonus = bonus;
		}

		int IComparable<Dragon>.CompareTo (Dragon other)
		{
			return this.Strength.CompareTo(other.Strength);
		}

	}

}


using System;
using System.Collections.Generic;
namespace dragon
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			string[] str = Console.ReadLine().Split(' ');
			int strength = int.Parse(str[0]), n = int.Parse(str[1]);
			Dragon[] dragons = new Dragon[n];
			for (int i = 0; i < n; i++)
			{
				str = Console.ReadLine().Split(' ');
				dragons[i] = new Dragon (int.Parse(str[0]), int.Parse(str[1]));
			}
			SortArray(dragons);
			foreach (Dragon dragon in dragons)
			{
				if (strength > dragon.Strength)
				{
					strength+=dragon.Bonus;
				}
				else
				{
					Console.WriteLine("NO");
					Environment.Exit(0); //telos
				}
			}
			Console.WriteLine("YES");
		}

		public static void SortArray<T> (T[] arr) where T:IComparable<T>
		{
			for (int i = 1; i < arr.Length; i++)
			{
				for (int j = arr.Length-1; j >= i; j--)
				{
					if (arr [j - 1].CompareTo(arr[j]) > 0)
					{
						T temp = arr [j - 1];
						arr [j - 1] = arr [j];
						arr [j] = temp;
					}
				}
			}
		}

	}

	 class Dragon : IComparable<Dragon>
	{
		public int Strength {get; private set;}
		public int Bonus {get; private set;}

		public Dragon (int strength, int bonus)
		{
			this.Strength = strength;
			this.Bonus = bonus;
		}

		int IComparable<Dragon>.CompareTo (Dragon other)
		{
			return this.Strength.CompareTo(other.Strength);
		}

	}

}