#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const double PI = 3.14159265358979323846;
const int mod = 1000000007;
int main(int argc, char *args[]) {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (m); ++i) {
    cin >> s[i] >> c[i];
  }
  int tmp = 0;
  priority_queue<int, vector<int>, greater<int>> Q;
  if (n == 3) {
    for (int i = 1; i <= 9; i++) {
      for (int j = 0; j <= 9; j++) {
        for (int k = 0; k <= 9; k++) {
          tmp = 100 * i + 10 * j + k;
          bool flag = true;
          for (int l = 0; l < (m); ++l) {
            if (s[l] == 1 && i != c[l]) flag = false;
            if (s[l] == 2 && j != c[l]) flag = false;
            if (s[l] == 3 && k != c[l]) flag = false;
          }
          if (flag) Q.push(tmp);
        }
      }
    }
  }
  if (n == 2) {
    for (int i = 1; i <= 9; i++) {
      for (int j = 0; j <= 9; j++) {
        tmp = 10 * i + j;
        bool flag = true;
        for (int l = 0; l < (m); ++l) {
          if (s[l] == 1 && i != c[l]) flag = false;
          if (s[l] == 2 && j != c[l]) flag = false;
        }
        if (flag) Q.push(tmp);
      }
    }
  }
  if (n == 1) {
    for (int i = 1; i <= 9; i++) tmp = i;
    bool flag = true;
    for (int l = 0; l < (m); ++l) {
      if (tmp != c[l]) flag = false;
    }
    if (flag) Q.push(tmp);
  }
  if (Q.empty())
    cout << -1 << endl;
  else
    cout << Q.top() << endl;
  return 0;
}
