#include <bits/stdc++.h>
using namespace std;
long long mob = 1000000007;
int main() {
  int n;
  int m;
  cin >> n >> m;
  int a[m][2];
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> a[i][j];
    }
  }
  string f = "1", s = "0", t = "0";
  string k;
  for (int i = 0; i < m; i++) {
    if (a[i][0] == 1) {
      f.pop_back();
      string p = to_string(a[i][1]);
      f = f + p;
    }
    if (a[i][0] == 2) {
      s.pop_back();
      string p = to_string(a[i][1]);
      s = s + p;
    }
    if (a[i][0] == 3) {
      t.pop_back();
      string p = to_string(a[i][1]);
      t = t + p;
    }
  }
  k = f + s + t;
  stringstream yo(k);
  int y;
  yo >> y;
  int r = floor(log10(y) + 1);
  if (r == n)
    cout << y;
  else
    cout << -1;
  return 0;
}
