#include <bits/stdc++.h>
using namespace std;
int cnt[30];
int32_t main() {
  int n, m;
  cin >> n >> m;
  int st[n];
  for (int i = 0; i < n; i++) st[i] = -1;
  while (m--) {
    int x, y;
    cin >> x >> y;
    --x;
    if (st[x] == -1)
      st[x] = y;
    else {
      if (st[x] != y) {
        cout << -1;
        return 0;
      }
    }
  }
  if (st[n - 1] == -1)
    cout << -1;
  else {
    for (int i = 0; i < n; ++i) {
      if (st[i] == -1)
        cout << 0;
      else
        cout << st[i];
    }
  }
}
