/+ dub.sdl:
    name "F"
    dependency "dunkelheit" version=">=0.9.0"
+/

import std.stdio, std.algorithm, std.range, std.conv, std.typecons;
// import dkh.foundation, dkh.scanner, dkh.container.pairingheap;

alias P = Tuple!(long, "d", int, "p");
alias Q = PairingHeap!(P, "a.d>b.d");

int main() {
    Scanner sc = new Scanner(stdin);

    int n, m;
    sc.read(n, m);
    int[][] g = new int[][n];
    long[] lw = new long[n], us = new long[n];
    foreach (i; 0..n) {
        sc.read(lw[i], us[i]); lw[i] -= us[i];
    }
    long off = us.sum;
    foreach (i; 0..m) {
        int a, b;
        sc.read(a, b); a--; b--;
        g[a] ~= b; g[b] ~= a;
    }
    Q[] gx = new Q[n];
    foreach (i; 0..n) {
        foreach (d; g[i]) {
            gx[i].insert(P(lw[d], d));
        }
    }

    int[] ig = new int[n];
    int[][] gi = new int[][n];
    foreach (i; 0..n) {
        ig[i] = i; gi[i] = [i];
    }
    auto uf_same = (int a, int b) => ig[a] == ig[b];
    void uf_merge(int a, int b) {
        if (uf_same(a, b)) return;
        int x = ig[a], y = ig[b];
        if (gi[x].length < gi[y].length) swap(x, y);
        foreach (d; gi[y]) ig[d] = x;
        gi[x] ~= gi[y]; gi[y] = [];

        us[x] += us[y];
        us[y] = 0;

        gx[x].meld(gx[y]);
    }

    long ans = 0;
    Q que;
    foreach (i; 0..n) {
        que.insert(P(lw[i], i));
    }
    bool[] vis = new bool[n];
    void on(int p) {
        vis[p] = true;
        foreach (d; g[p]) {
            if (vis[d]) uf_merge(p, d);
        }
        int x = ig[p];
        while (gx[x].length) {
            auto tp = gx[x].front();
            if (vis[tp.p]) {
                gx[x].removeFront();
                continue;
            }
            if (tp.d <= ans+us[x]) {
                on(tp.p);
            } else {
                que.insert(P(tp.d - us[x], tp.p));
            }
            break;
        }
    }

    while (que.length) {
        P tp = que.front; que.removeFront();
        int p = tp.p;
        if (vis[p]) continue;
        ans = max(ans, tp.d);
        on(p);
    }
    writeln(ans+off);
    return 0;
}
/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */
// module dkh.container.stackpayload;

 
struct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {
    import core.exception : RangeError;

    private T* _data;
    private uint len, cap;

    @property bool empty() const { return len == 0; }
    @property size_t length() const { return len; }
    alias opDollar = length;

     
    inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }
    
    ref inout(T) opIndex(size_t i) inout {
        version(assert) if (len <= i) throw new RangeError();
        return _data[i];
    }  
    ref inout(T) front() inout { return this[0]; }  
    ref inout(T) back() inout { return this[$-1]; }  

    void reserve(size_t newCap) {
        import core.memory : GC;
        import core.stdc.string : memcpy;
        import std.conv : to;
        if (newCap <= cap) return;
        void* newData = GC.malloc(newCap * T.sizeof);
        cap = newCap.to!uint;
        if (len) memcpy(newData, _data, len * T.sizeof);
        _data = cast(T*)(newData);
    }  
    void free() {
        import core.memory : GC;
        GC.free(_data);
    }  
     
    void clear() {
        len = 0;
    }

    void insertBack(T item) {
        import std.algorithm : max;
        if (len == cap) reserve(max(cap * 2, MINCAP));
        _data[len++] = item;
    }  
    alias opOpAssign(string op : "~") = insertBack;  
    void removeBack() {
        assert(!empty, "StackPayload.removeBack: Stack is empty");
        len--;
    }  
}

 
/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/scanner.d */
// module dkh.scanner;

// import dkh.container.stackpayload;

 
class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray; 
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    char[512] lineBuf;
    char[] line;
    private bool succW() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (!line.empty && line.front.isWhite) {
            line.popFront;
        }
        return !line.empty;
    }
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            line = lineBuf[];
            f.readln(line);
            if (!line.length) return false;
        }
        return true;
    }

    private bool readSingle(T)(ref T x) {
        import std.algorithm : findSplitBefore;
        import std.string : strip;
        import std.conv : parse;
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {
                 
                 
                auto r = line.findSplitBefore(" ");
                x = r[0].strip.dup;
                line = r[1];
            } else static if (isStaticArray!T) {
                foreach (i; 0..T.length) {
                    bool f = succW();
                    assert(f);
                    x[i] = line.parse!E;
                }
            } else {
                StackPayload!E buf;
                while (succW()) {
                    buf ~= line.parse!E;
                }
                x = buf.data;
            }
        } else {
            x = line.parse!T;
        }
        return true;
    }

    int unsafeRead(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
    void read(bool enforceEOF = false, T, Args...)(ref T x, auto ref Args args) {
        import std.exception;
        enforce(readSingle(x));
        static if (args.length == 0) {
            enforce(enforceEOF == false || !succ());
        } else {
            read!enforceEOF(args);
        }
    }
    void read(bool enforceEOF = false, Args...)(auto ref Args args) {
        import std.exception;
        static if (args.length == 0) {
            enforce(enforceEOF == false || !succ());
        } else {
            enforce(readSingle(args[0]));
            read!enforceEOF(args);
        }
    }
}


 
 

 
/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/container/pairingheap.d */
// module dkh.container.pairingheap;

private NP meldPairingHeapNode(alias less, NP)(NP x, NP y) {
    import std.algorithm : swap;
    if (!x) return y;
    if (!y) return x;
    if (less(x._item, y._item)) swap(x, y);
    y.next = x.head;
    x.head = y;
    return x;
}

 
struct PairingHeap(T, alias less = "a < b") {
    import std.functional : binaryFun;
    private alias _less = binaryFun!less;

    private alias NP = Node*;
    private static struct Node {
        T _item;
        NP head, next;
        this(T item) {
            _item = item;
        }
    }

    private struct Payload {
        import std.algorithm : swap;
        private NP node;
        private uint len;

        void insert(T item) {
            len++;
            node = meldPairingHeapNode!_less(node, new Node(item));
        }
        inout(T) front() inout { return node._item; }
        void removeFront() {
            len--;

            NP s = node.head;
            NP t;
             
             
            while (s) {
                 
                NP first, second;
                first = s; s = s.next; first.next = null;
                if (s) {
                    second = s; s = s.next; second.next = null;
                }
                 
                auto v = meldPairingHeapNode!_less(first, second);
                v.next = t;
                t = v;
            }
            node = null;
             
            while (t) {
                NP first = t; t = t.next; first.next = null;
                node = meldPairingHeapNode!_less(first, node);
            }
        }
        void meld(Payload* r) {
            len += r.len; r.len = 0;
            node = meldPairingHeapNode!_less(node, r.node);
            r.node = null;
        }
    }
    private Payload* _p;

    @property bool empty() const { return !_p || _p.len == 0; }  
    @property size_t length() const { return (!_p) ? 0 : _p.len; }  

    void insert(T item) {
        if (!_p) _p = new Payload();
        _p.insert(item);
    }  
    inout(T) front() inout {
        assert(!empty, "PairingHeap.front: heap is empty");
        return _p.front;
    }  
    void removeFront() {
        assert(!empty, "PairingHeap.removeFront: heap is empty");
        _p.removeFront;
    }  
     
    void meld(PairingHeap r) { _p.meld(r._p); }
}

 
 

 

 
/* IMPORT /mnt/c/Users/yosupo/Programs/dunkelheit/source/dkh/foundation.d */
 
// module dkh.foundation;

 
static if (__VERSION__ <= 2070) {
    /*
    Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d
    Copyright: Andrei Alexandrescu 2008-.
    License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
    */
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            import std.algorithm : reduce;
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                import std.typecons : tuple;
                return reduce!fun(tuple(seed), r);
            }
        }
    }
     
}

/*
This source code generated by dunkelheit and include dunkelheit's source code.
dunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)
dunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)
*/


Measured memory_bytes: 25596