#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const int INF = 1000000000; // 10^9
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N,M;
    cin >> N >> M;
    vector<int> v(N);

    for (int i = 0; i < M; i++){
        int s, c;
        cin >> s >> c;
        s--;
        if(v[s] != 0){
            v[s] = min(v[s], c);
        } else {
            v[s] = c;
        }
    }

    if(N == 1 && v[0] == 0){
        cout << 0 << endl;
        return 0;
    }

    if(v[0] == 0){
        cout << "-1" << endl;
        return 0;
    }

    for (int i = 0; i < M; i++){
        cout << v[i];
    }

    cout << endl;
}
