#include"../bits/stdc++.h"
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int compNum(int oldNum, int newNum) {
    if(oldNum == 0) return newNum;
    return min(oldNum, newNum);
} 

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> result(N);
    int res = 0;
    vector<int> s(M);
    vector<int> c(M);
    rep(i, M) {
        cin >> s[i] >> c[i];
        result[s[i]-1] = compNum(result[s[i]-1], c[i]);
    }
    if (result.size() > 1 && result[0] == 0) {
        cout << -1 << endl;
        return 0;
    }
    rep(i, N) {
        res += result[N - i - 1] * pow(10, i);
    }
    cout << res << endl;
}