#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> str(n + 1);
  vector<int> s(m + 1);
  vector<int> c(m + 1);
  if (m > 0) {
    for (int i = 1; i < m + 1; i++) cin >> s[i] >> c[i];
  }
  for (int i = 1; i < n + 1; i++) str[i] = 0;
  str[1] = 1;
  set<int> st1, st2, st3;
  for (int i = 1; i < m + 1; i++) {
    if (s[i] > n) {
      cout << -1 << endl;
      return 0;
    } else {
      switch (s[i]) {
        case 1:
          st1.insert(c[i]);
          break;
        case 2:
          st2.insert(c[i]);
          break;
        case 3:
          st3.insert(c[i]);
          break;
      }
    }
  }
  if (st1.size() > 1 || st2.size() > 1 || st3.size() > 1) {
    cout << -1 << endl;
    return 0;
  } else {
    for (int i = 1; i < m + 1; i++) str[s[i]] = c[i];
  }
  if (str[1] == 0) {
    cout << -1 << endl;
  } else {
    for (int i = 1; i < n + 1; i++) cout << str[i];
    cout << endl;
  }
}
