import std.stdio, std.conv, std.string, std.algorithm, std.math, std.array, std.container;

int solve() {
  int n, m;
  readf("%d %d\n", &n, &m);
  int[] cond_d = new int[m];
  int[] cond_v = new int[m];
  for(int i=0; i<m; i++) {
    readf("%d %d\n", &cond_d[i], &cond_v[i]);
  }
  int[4] ten = [-1,1,10,100];
  for(int i=ten[n]; i<ten[n]*10; i++) {
    bool br = false;
    for(int j=0; j<m; j++) {
      if(((i/ten[n-cond_d[j]+1]) % 10) != cond_v[j]) {
        br = true;
        break;
      }
    }
    if(!br) return i;
  }
  return -1;
}

void main() {
  writeln(solve());
}

