#include <iostream>
using namespace std;

int main() {
    int n, m; cin >> n >> m;
    int A[n+1] = {};
    int flag = 0;
    for (int i = 0; i < m; i++) {
        int s, c; cin >> s >> c;
        if ((A[s-1] != c && A[s-1] != 0) || n < s) flag = 1;
        else A[s-1] = c;
    }
    string ans = "";
    for (int i = 0; i < n; i++) ans += A[i] + '0';
    if (flag || (n!=1 && ans[0] == '0') || ans.size() != n)  { puts("-1"); return 0; }
    cout << ans << endl;
}