#include <bits/stdc++.h>
using ll = long long;
using namespace std;
using Graph = vector<vector<int>>;
int main() {
  int n, m;
  cin >> n >> m;
  int s[5] = {};
  int c[5] = {};
  for (int i = 0; i < (m); ++i) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < (pow(10, n)); ++i) {
    int cnt = 0;
    for (int j = 0; j < (m); ++j) {
      int first = i % 10;
      int middle = (i / 10) % 10;
      int last = i / 100;
      if (s[j] == 1 && c[j] == last && last != 0) cnt++;
      if (s[j] == 2 && c[j] == middle && middle != 0) cnt++;
      if (s[j] == 3 && c[j] == first) cnt++;
    }
    if (cnt == m) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
