import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    // 変数一覧
    int n;
    int m;
    long[] a;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        a = new long[m];
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextLong();
        }
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        for (int i = 0; i < a.length; i++) {
            n -= a[i];
            if (n < 0) {
                System.out.println("-1");
                break;
            }
            if (i == m-1) {
                System.out.println(n);
            }
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    // 変数一覧
    int n;
    int m;
    long[] a;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        a = new long[m];
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextLong();
        }
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        for (int i = 0; i < a.length; i++) {
            n -= a[i];
            if (n < 0) {
                System.out.println("-1");
                break;
            }
            if (i == m-1) {
                System.out.println(n);
            }
        }
    }
} Main // 変数一覧
    int n; n int m; m long[] a; a public static void main(String[] args) {
        Main main = new Main();
        main.run();
    } main {
        Main main = new Main();
        main.run();
    } Main main = new Main(); main new Main() main.run() main.run main String[] args args public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        a = new long[m];
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextLong();
        }
        sc.close();

        // 解答処理
        solve();
    } run {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        a = new long[m];
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextLong();
        }
        sc.close();

        // 解答処理
        solve();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n = sc.nextInt() n sc.nextInt() sc.nextInt sc m = sc.nextInt() m sc.nextInt() sc.nextInt sc a = new long[m] a new long[m] m for (int i = 0; i < m; i++) {
            a[i] = sc.nextLong();
        } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
            a[i] = sc.nextLong();
        } {
            a[i] = sc.nextLong();
        } a[i] = sc.nextLong() a[i] a i sc.nextLong() sc.nextLong sc sc.close() sc.close sc solve() solve private void solve() {
        for (int i = 0; i < a.length; i++) {
            n -= a[i];
            if (n < 0) {
                System.out.println("-1");
                break;
            }
            if (i == m-1) {
                System.out.println(n);
            }
        }
    } solve {
        for (int i = 0; i < a.length; i++) {
            n -= a[i];
            if (n < 0) {
                System.out.println("-1");
                break;
            }
            if (i == m-1) {
                System.out.println(n);
            }
        }
    } for (int i = 0; i < a.length; i++) {
            n -= a[i];
            if (n < 0) {
                System.out.println("-1");
                break;
            }
            if (i == m-1) {
                System.out.println(n);
            }
        } int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
            n -= a[i];
            if (n < 0) {
                System.out.println("-1");
                break;
            }
            if (i == m-1) {
                System.out.println(n);
            }
        } {
            n -= a[i];
            if (n < 0) {
                System.out.println("-1");
                break;
            }
            if (i == m-1) {
                System.out.println(n);
            }
        } n -= a[i] n a[i] a i if (n < 0) {
                System.out.println("-1");
                break;
            } n < 0 n 0 {
                System.out.println("-1");
                break;
            } System.out.println("-1") System.out.println System.out System System.out "-1" break; if (i == m-1) {
                System.out.println(n);
            } i == m-1 i m-1 m 1 {
                System.out.println(n);
            } System.out.println(n) System.out.println System.out System System.out n public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    // 変数一覧
    int n;
    int m;
    long[] a;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        a = new long[m];
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextLong();
        }
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        for (int i = 0; i < a.length; i++) {
            n -= a[i];
            if (n < 0) {
                System.out.println("-1");
                break;
            }
            if (i == m-1) {
                System.out.println(n);
            }
        }
    }
} public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    // 変数一覧
    int n;
    int m;
    long[] a;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        a = new long[m];
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextLong();
        }
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        for (int i = 0; i < a.length; i++) {
            n -= a[i];
            if (n < 0) {
                System.out.println("-1");
                break;
            }
            if (i == m-1) {
                System.out.println(n);
            }
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    // 変数一覧
    int n;
    int m;
    long[] a;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        a = new long[m];
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextLong();
        }
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        for (int i = 0; i < a.length; i++) {
            n -= a[i];
            if (n < 0) {
                System.out.println("-1");
                break;
            }
            if (i == m-1) {
                System.out.println(n);
            }
        }
    }
}