#include <bits/stdc++.h>
int faster_in() {
  int r = 0, c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  if (c == '-') return -faster_in();
  for (; c > 32; r = (r << 1) + (r << 3) + c - '0', c = getchar())
    ;
  return r;
}
using namespace std;
const int INF = int(1e9 + 7);
const double PI = acos(-1);
const double EPS = 1e-9;
int val[1000];
int main() {
  memset(val, -1, sizeof val);
  int n, m;
  cin >> n >> m;
  int pos, num;
  bool invalid = 0;
  for (int i = 0; i < m; i++) {
    cin >> pos >> num;
    pos = n - pos;
    if (val[pos] != -1) {
      if (num != val[pos]) invalid = 1;
    }
    val[pos] = num;
  }
  if (val[n - 1] == 0)
    invalid = 1;
  else
    val[n - 1] = 1;
  if (invalid)
    cout << "-1";
  else {
    for (int i = n - 1; i >= 0; i--) {
      if (val[i] == -1)
        cout << 0;
      else
        cout << val[i];
    }
  }
}
