#include <bits/stdc++.h>
using namespace std;
signed main(void) {
  int n, m, a[4];
  cin >> n >> m;
  memset(a, -1, sizeof(a));
  for (int i = 1; i <= m; i++) {
    int c, b;
    cin >> c >> b;
    if (a[4 - c] != -1 && a[4 - c] != b) {
      cout << -1;
      return 0;
    } else {
      a[4 - c] = b;
    }
  }
  if (a[4 - n] == -1) {
    cout << -1;
    return 0;
  }
  for (int i = 3; i >= 4 - n; i--) {
    if (a[i] == -1)
      cout << 0;
    else
      cout << a[i];
  }
  return 0;
}
