#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  vector<pair<int, int> > a(m, {0, 0});
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a[i].first, &a[i].second);
    a[i].first--;
  }
  for (int i = 0; i < 1000; i++) {
    int l = 0;
    vector<int> v;
    for (int j = i; j > 0; j /= 10) {
      l++;
      v.push_back(j % 10);
    }
    if (i == 0) l++;
    if (l != n) continue;
    reverse(v.begin(), v.end());
    int bad = 0;
    for (int k = 0; k < m; k++) {
      if (v[a[k].first] != a[k].second) {
        bad = 1;
        break;
      }
    }
    if (!bad) {
      printf("%d\n", i);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
