#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin >> n >> m;
    int num[n] = {0};
    int flag[n] = {0};
    int s,c;
    bool no = false;
    for(int i = 0 ; i < m ; i++){
        cin >> s >> c;
        if(flag[s - 1] && num[s - 1] != c)
            no = true;

        num[s - 1] = c;
        flag[s - 1] = 1;
    }
    
    if(num[0] == 0)
        no = true;

    if(n == 1 || m == 0){
        no = false;
        n = 1;
    }
    
    if(no)
        cout << -1;
    else
        for(int i = 0 ; i < n ; i++)
            cout << num[i];
    
    cout << endl;
  
    return 0;
}