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