#include <bits/stdc++.h>
using namespace std;
int n, m, a[10];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  int x, y;
  memset(a, -1, sizeof(a));
  int flag = 0;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    if (a[x] == -1)
      a[x] = y;
    else if (a[x] != y) {
      flag = 1;
    }
  }
  if (flag || (n > 1 && a[1] == 0))
    puts("-1");
  else {
    if (n == 1 && a[1] == -1)
      puts("0");
    else {
      if (a[1] == -1) a[1] = 1;
      if (a[2] == -1) a[2] = 0;
      if (a[3] == -1) a[3] = 0;
      for (int i = 1; i <= n; i++) cout << a[i];
      cout << endl;
    }
  }
}
