#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int main() {
  int N, M;
  int s[M], c[M];
  cin >> N >> M;
  for (int i = 0; i < (int)(M); i++) cin >> s[i] >> c[i];
  vector<bool> can(1000, true);
  for (int i = 0; i <= 999; i++) {
    for (int j = 0; j < M; j++) {
      if (s[j] = 1) {
        int a = i / 100;
        if (a != c[j]) can[i] = false;
      }
      if (s[j] = 2) {
        int b = i % 100 / 10;
        if (b != c[j]) can[i] = false;
      }
      if (s[j] = 3) {
        int d = i % 10;
        if (d != c[j]) can[i] = false;
      }
    }
    if (can[i]) cout << i << endl;
    break;
  }
  bool flag = false;
  for (int i = 0; i < 1000; i++) {
    if (!can[i])
      flag = true;
    else
      flag = false;
  }
  if (flag) cout << -1 << endl;
}
