/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{   
    int n = 0, m = 0, a = 0, b = 0 ;
    cin >> n >> m; 
    int array[n] = {0};
    vector<pair<int,int>> cor;
    for(int i = 0; i < m; i ++){
        cin >> a >> b; 
        cor.push_back(make_pair(a,b));
    }
    
    for(int i = 0; i < cor.size(); i++){
        if(array[cor[i].first - 1] == 0 || array[cor[i].first - 1] == cor[i].second){
            
            array[cor[i].first - 1] = cor[i].second;
            
        }else{
            cout << -1;
            return 0;
        }
    }
    
    if(array[0] == 0){
        cout << -1;
        return 0;
    }else{
        for (int i = 0; i < n; i++){
            cout << array[i];
        }
    }
    
    
    return 0;
}