#include<iostream>

using namespace std;

int main(){
    int n,m,i,s,c,ans = 0,flag = 1;
    cin>>n>>m;
    int a[n+1] = {0};
    for(i=1;i<=n;i++){
        cin>>s>>c;
        if(a[s] == 0){
            if(a[s] != c) flag = 0;
        }
        a[s] = c;
    }
    for(i=1;i<=n;i++){
        ans = ans*10 + a[i];
    }
    if(flag == 1) cout<<ans<<endl;
    else cout<<-1<<endl;
}