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

int main(void){
    int n,m;
    cin >> n >> m;
    int s[m],c[m];
    for(int i = 0;i < m;i++)cin >> s[i] >> c[i];
    bool check = true;
    int a[n];
    for(int j = 0;j < m;j++){
        for(int k = 0;k < m;k++){
            if(j == k)continue;
            if(s[j] == s[k] && c[j] != c[k])check = false;
        }
    }
    if(!check)cout << -1 << endl;
    else if(n == 1){
        for(int i = 0;i < m;i++){
            if(s[i] == 1 && c[j] == 0)check = false;
        }
        if(!check)cout << -1 << endl;
    } else {
        for(int i = 0;i < n;i++){
            int b = 0;
            for(int j = 0;j < m;j++){
                if(i+1 == s[j])b = c[j];
            }
            a[i] = b;
        }
        for(int i = 0;i < n;i++){
            if(i == 0 && a[i] == 0)cout << 1;
            else cout << a[i];
        }
        cout << endl;
    }
}
