#include <bits/stdc++.h>
using namespace std;
struct node {
  int s = 0;
  int num = 0;
};
int main() {
  int n, m;
  while (cin >> n >> m) {
    node a[6];
    int flag = 1;
    map<int, node> p;
    int s[5];
    s[1] = -1;
    s[2] = -1;
    s[3] = -1;
    s[4] = -1;
    for (int i = 0; i < m; i++) {
      int x;
      cin >> x;
      cin >> p[x].s;
      p[x].num++;
      if (p[x].num > 1) {
        if (p[x].s != s[x]) flag = 0;
      }
      s[x] = p[x].s;
      if (x == 1 && p[x].s == 0 && n != 1) flag = 0;
    }
    if (n == 1 && m == 0) {
      cout << 0 << endl;
      continue;
    }
    if (flag == 0) {
      cout << -1 << endl;
      continue;
    }
    if (n == 1 && p[1].s == 0) {
      cout << 0 << endl;
      continue;
    }
    if (n != 1 && p[1].s == 0 && p[1].num == 0) {
      cout << -1 << endl;
      continue;
    }
    for (int i = 1; i <= n; i++) {
      if (s[i] == -1 && i == 1)
        cout << 1;
      else if (s[i] == -1)
        cout << 0;
      else
        cout << s[i];
    }
    cout << endl;
  }
  return 0;
}
