#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < 1000; i++) {
    bool flag = true;
    for (int j = 0; j < M; j++) {
      int tmp = i;
      if (s[j] == 1 && j < 100) {
        flag = false;
        break;
      }
      if (s[j] == 2 && j < 10) {
        flag = false;
        break;
      }
      if (s[j] == 1)
        tmp /= 100;
      else if (s[j] == 2)
        tmp /= 10;
      tmp %= 10;
      if (tmp != c[j]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
