#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const int N = 2e5 + 5;
int n, m, s, c, num[4];
int(main)() {
  cin >> n >> m;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  memset(num, -1, sizeof num);
  while (m--) {
    cin >> s >> c;
    if (s == 1 && c == 0) {
      cout << -1;
      return 0;
    }
    if (num[s] == -1) {
      num[s] = c;
    } else {
      if (num[s] != c) {
        cout << -1;
        return 0;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (num[i] == -1)
      cout << 0;
    else
      cout << num[i];
  }
}
