#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int c[m][2];
  for (int i = 0; i < m; i++) {
    cin >> c[i][0] >> c[i][1];
  }
  for (int ans = 0; ans < 1000; ans++) {
    int keta = 0;
    if (ans / 100 > 0) {
      keta = 3;
    } else if (ans / 10 > 0) {
      keta = 2;
    } else {
      keta = 1;
    }
    bool check1 = false;
    bool check = false;
    if (keta == n) {
      check1 = true;
      int cnt = 0;
      for (int i = 0; i < m; i++) {
        int ans100 = ans / 100;
        int ans10 = ans - ans100 * 100;
        int ans1 = ans - ans100 * 100 - ans10 / 10 * 10;
        if (c[i][0] == 1) {
          if (ans100 == c[i][1]) {
            cnt++;
          }
        } else if (c[i][0] == 2) {
          if (ans10 == c[i][1]) {
            cnt++;
          }
        } else {
          if (ans1 == c[i][1]) {
            cnt++;
          }
        }
      }
      if (cnt == m) {
        check = true;
      }
      if (check1 == true && check == true) {
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
}
