    #include<bits/stdc++.h>
     
    using namespace std;
     int vec[3],vec2[3];
     
    int main(){
        bool flag = true;
        int n,m ,s ,c;

        cin >> n >> m;

        if(n == 1 && m == 0){
            cout<<0 << "\n";
            return 0;
        }
        for (int i = 0; i < m; i++)
        {
            cin >> s >> c;

            if(n >1 && s == 1 && c == 0){
                vis = false;
                continue;
            }
            else if(c != vec[n-s] && vec[n-s]> 0){
                flag = false;
                continue;
            }
            vec[n-s] = c;
            vec2[n-s]++;
            

        }
        
        if(flag){
        
        if(vec[2] == 0 && vec[1] == 0 && n == 3)
            cout<< 100+vec[0]<< "\n";
        
        else if(vec[2] == 0 && n == 3)
            cout<< 100 + vec[1]*10 + vec[0]<< "\n";
        else if(vec[1] == 0 && n == 2)
            cout<< 10+vec[0]<< "\n";
        else if( n == 1)
            cout<< vec[0]<< "\n";
        
        else{
            cout<< 100*vec[2] + 10*vec[1] +vec[0] << "\n";
        }
            }
        else{
            cout<< "-1"<< "\n";
        }

       return 0;
    }