#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n + 1];
  memset(a, -1, sizeof(a));
  int f = 0;
  int x, y;
  int g = 0;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    if (a[x] != -1) {
      if (a[x] != y) f = 1;
    } else
      a[x] = y;
  }
  if (a[1] == -1 and n != 1) f = 1;
  if (f)
    cout << -1 << "\n";
  else {
    for (int i = 1; i <= n; i++) {
      if (a[i] != -1)
        cout << a[i];
      else
        cout << 0;
    }
    cout << "\n";
  }
  return 0;
}
