#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> v1(m + 7);
vector<int> v(m + 7);
map<int, int> mp;
int main() {
  string s = "";
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, s;
    cin >> x >> s;
    if (v1[x] == 0) {
      v1[x] = 1;
      v[x - 1] = s;
      mp[x] = s;
    } else {
      if (mp[x] != s) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (v[0] == 0) {
    cout << -1 << endl;
    return 0;
  } else {
    for (int i = 0; i < m; i++) {
      cout << v[i];
    }
    cout << endl;
  }
}
