#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[n + 1];
  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;
        break;
      }
    }
  }
  if (w == 1)
    cout << -1;
  else {
    for (i = 1; i <= n; i++) {
      if (a[i] == 0) sum++;
      if (a[i] != 0) {
        break;
      }
    }
    if (sum > 0)
      cout << -1;
    else {
      for (i = 1; i <= n; i++) cout << a[i];
    }
  }
  return 0;
}
