#include <bits/stdc++.h>
using namespace std;

int main(){
    int N, M; cin >> N >> M;
    vector<int> s_al(N,-1);

    if( N == 1 ){

        int s, c;
        for( int i = 0; i < M; i++ ){
            cin >> s >> c;
            if( s_al[0] != c && s_al[0] != -1 ){
                cout << "-1" << endl;
                return 0;
            } else {
                s_al[0] = c;
            }
        }

        if( s_al[0] == -1 ) s_al[0] = 0;

        cout << s_al[0] << endl;

    } else {

        int s, c;
        for( int i = 0; i < M; i++ ){
            cin >> s >> c;
            if( s_al[s-1] != -1 && s_al[s-1] != c ){
                cout << "-1" << endl;
                return 0;
            } else if ( s == 0 && c == 0 ){
                cout << "-1" << endl;
                return 0;
            } else {
                s_al[s-1] = c;
            }
        }

        for( int i = 0; i < N; i++ ){
            if( s_al[i] == -1 && i == 0 ) s_al[i] = 1;
            if( s_al[i] == -1 && i != 0 ) s_al[i] = 0;
        }

        reverse(s_al.begin(),s_al.end());
        int ans = 0;
        if( s_al == {0,0,-1} ) ans = 0;
        else{
            for( int i = 0; i < N; i++ ){
                ans += s_al[i] * pow(10,i);
            }
        }

        cout << ans << endl;

    }
}