#include <bits/stdc++.h>
using namespace std;
int b[4];
struct node {
  int a1, b1;
} a[6];
int main() {
  int n, m, i;
  cin >> n >> m;
  for (i = 1; i <= m; i++) cin >> a[i].a1 >> a[i].b1;
  for (i = 1; i <= m; i++) {
    if (b[a[i].a1] != 0)
      for (int j = 1; j < i; j++)
        if (a[j].a1 == a[i].a1) {
          if (a[j].b1 != a[i].b1) {
            cout << "-1";
            return 0;
          }
        }
    if (a[i].a1 == 1 && a[i].b1 == 0) {
      cout << "-1";
      return 0;
    }
    if (a[i].a1 > n) {
      cout << "-1";
      return 0;
    }
    b[a[i].a1] = a[i].b1;
  }
  if (b[3 - n + 1] == 0) b[3 - n + 1] = 1;
  for (i = 1; i <= n; i++) cout << b[i];
  return 0;
}
