#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int main() {
  int n, m, i, j, k, l, r, sum = 0, w = 0;
  int v[500];
  memset(v, 0, sizeof(v));
  cin >> n >> m;
  int a[50];
  memset(a, 0, sizeof(a));
  for (i = 1; i <= m; i++) {
    cin >> l >> r;
    if (v[l] == 0) {
      v[l] = 1;
      a[l] = r;
    } else {
      if (r != a[l]) {
        w = 1;
      }
    }
  }
  if (w == 1)
    cout << -1;
  else {
    if (a[1] == 0 && n != 1) a[1] = 1;
    for (i = 1; i <= n; i++) cout << a[i];
  }
  return 0;
}
