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

int main() {
    int N, M;
    int s[M] = {}, c[M] = {}, ans[M] = {};
    cin >> N >> M;
    for (int i = 0; i < M; i++)
    {
        cin >> s[i] >> c[i];
      	s[i]--;
    }
    for(int i=0; i < N; i++)
    {
        ans[i] = -1;
    }
    bool tf = 1;
    for (int i = 0; i < M; i++)
    {
        if(ans[s[i]] == -1){
            ans[s[i]] = c[i];
        }else{
            if(ans[s[i]] != c[i]) tf = 0;
        }
    }
    if(N>1){
        if(ans[0] == 0) tf = 0;
    }
    if(N==1){
        if(ans[0] == -1){
            cout << 0;
        }else{
            cout << ans[0];
        }
    }else{
    if(tf){
        if(ans[0] == -1){
            cout << 1;
        }else{
            cout << ans[0];
        }
        for (int i = 1; i < N; i++)
        {
            if(ans[i] == -1){
                cout << 0;
            }else{
                cout << ans[i];
            }
        }
        
    }else{
        cout << -1 << endl;
    }}
}