#include <bits/stdc++.h>
using namespace std;
long long int ara[4], mark[15];
int main() {
  memset(mark, -1, sizeof(mark));
  memset(ara, -1, sizeof(ara));
  int n, m, a, b, ok = 1;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (mark[a] != -1) {
      if (b != mark[a]) ok = 0;
    }
    ara[a] = b;
    mark[a] = b;
  }
  if (ara[1] == -1 && ara[2] == -1 && ara[3] != -1) {
    ara[1] = 1;
    ara[2] = 0;
  }
  if (ara[1] == -1 && ara[2] != -1) {
    ara[1] = 1;
    if (ara[3] == -1) ara[3] = 0;
  }
  if (ara[1] != -1) {
    if (ara[2] == -1) ara[2] = 0;
    if (ara[3] == -1) ara[3] = 0;
  }
  if (ara[1] == 0 || ara[1] == -1) ok = 0;
  if (ok)
    for (int i = 1; i <= n; i++) cout << ara[i];
  else
    cout << "-1" << endl;
  return 0;
}
