#include <bits/stdc++.h>

using namespace std;

int v[15];

int main(){
    int n,m,i,s,c,k=0,answer=0;

    cin>>n>>m;

    for(i=1;i<=m;i++){
        cin>>s>>c;
        v[s]=c;
    }

    for(i=1;i<=n;i++){
        answer=answer*10+v[i];

        if(answer)
            k++;
    }

    if((!answer && n==1) || n==k)
        cout<<answer;
    else
        cout<<"-1";

    return 0;
}
