#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    a.push_back({x, y});
  }
  if (m == 0) {
    cout << (pow(10, n) - 1);
    return 0;
  }
  int i1 = 0;
  if (n == 2)
    i1 = 10;
  else
    i1 = 100;
  for (int i = i1; i < pow(10, n); i++) {
    bool t = 1;
    for (int j = 0; j < m; j++) {
      int s = a[j].first;
      int c = a[j].second;
      int num;
      if (s == 1) {
        if (n == 3) num = i / 100;
        if (n == 2) num = i / 10;
        if (n == 1) num = i;
      } else if (s == 2) {
        if (n == 3) num = (i / 10) % 10;
        if (n == 2) num = i % 10;
      } else
        num = i % 10;
      t = t & (num == c);
    }
    if (t) {
      cout << i;
      return 0;
    }
  }
  cout << "-1";
}
