#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m, box[4][10] = {0};
  int x, y, flg, flg2, sum, i, j;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    box[x][y] = 1;
  }
  flg = 0;
  for (i = 1; i <= n; i++) {
    sum = 0;
    for (j = 0; j <= 9; j++) {
      sum += box[i][j];
    }
    if (sum > 1) {
      flg = 1;
      break;
    }
  }
  if (box[1][0] == 1) flg = 1;
  if (flg == 0) {
    for (i = 1; i <= n; i++) {
      flg2 = 0;
      for (j = 0; j <= 9; j++) {
        if (box[i][j] == 1) {
          flg2 = 1;
          x = j;
        }
      }
      if (flg2 == 1)
        cout << x;
      else
        cout << 0;
    }
    cout << endl;
  } else
    cout << -1 << endl;
  return 0;
}
