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

    // for (int i = 0; i < n; i++)
    //     cout << num[i];

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

    return 0;
}