#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m;
  int s, c;
  int a[3];
  bool f[3];
  memset(f, 1, sizeof(f));
  memset(a, 0, sizeof(a));
  a[0] = 1;
  bool ff = 1;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> s >> c;
    if (f[s - 1] == 0) {
      if (a[s - 1] != c) {
        ff = 0;
      }
    } else {
      a[s - 1] = c;
    }
    f[s - 1] = 0;
  }
  if (a[0] == 0 || ff == 0) {
    cout << "-1";
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    cout << a[i];
  }
  return 0;
}
