#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int vis[n], a[n];
  memset(vis, -1, sizeof vis);
  memset(a, 0, sizeof a);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    --s;
    if (vis[s] != -1 && a[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    a[s] = c;
    vis[s] = 1;
  }
  if (a[0] == 0) {
    if (vis[0] != -1) return cout << -1, 0;
    a[0] = 1;
  }
  for (int i = 0; i < n; i++) {
    cout << a[i];
  }
  cout << endl;
  return 0;
}
