#include<iostream>

using namespace std;

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

}