#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (m == 0) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (int)(m); i++) {
    cin >> s[i];
    cin >> c[i];
  }
  vector<bool> a(1000);
  for (int i = 0; i < (int)(1000); i++) {
    a[i] = true;
  }
  switch (n) {
    case 1:
      for (int i = 0; i < m; i++) {
        for (int j = 0; j < 10; j++) {
          if (a[j]) {
            if (j != c[i]) {
              a[j] = false;
            }
          }
        }
      }
      for (int i = 0; i < 10; i++) {
        if (a[i]) {
          cout << i << endl;
          return 0;
        }
      }
      cout << -1 << endl;
      return 0;
    case 2:
      for (int i = 0; i < m; i++) {
        for (int j = 10; j < 100; j++) {
          if (a[j]) {
            if (s[i] == 1) {
              if ((j / 10) != c[i]) {
                a[j] = false;
              }
            } else {
              if ((j % 10) != c[i]) {
                a[j] = false;
              }
            }
          }
        }
      }
      for (int i = 10; i < 100; i++) {
        if (a[i]) {
          cout << i << endl;
          return 0;
        }
      }
      cout << -1 << endl;
      return 0;
    case 3:
      for (int i = 0; i < m; i++) {
        for (int j = 100; j < 1000; j++) {
          if (a[j]) {
            if (s[i] == 1) {
              if ((j / 100) != c[i]) {
                a[j] = false;
              }
            } else if (s[i] == 2) {
              if ((j / 10) != c[i]) {
                a[j] = false;
              }
            } else {
              if ((j % 10) != c[i]) {
                a[j] = false;
              }
            }
          }
        }
      }
      for (int i = 100; i < 1000; i++) {
        if (a[i]) {
          cout << i << endl;
          return 0;
        }
      }
      cout << -1 << endl;
      return 0;
  }
}
