#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n, m;
  cin >> n >> m;
  long long a[n + 1];
  memset(a, 0, sizeof(a));
  bool can = true;
  vector<long long> vis(n, 0);
  long long p = m;
  while (p--) {
    long long x, y;
    cin >> x >> y;
    x--;
    if (vis[x] && y != a[x]) {
      can = false;
      break;
    }
    vis[x] = 1;
    a[x] = y;
  }
  string l = "";
  if (!vis[0]) {
    a[0] = 1;
  }
  for (long long i = 0; i < n; i++) {
    l += (a[i] + '0');
  }
  if (l.length() < n || l.length() > n || can == false ||
      (l[0] == '0' && n != 1)) {
    cout << -1;
    return 0;
  }
  cout << l;
}
