#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> data(m, vector<int>(2));
  for (int i = 0; i < (m); i++) {
    for (int j = 0; j < (2); j++) cin >> data[i][j];
  }
  int ans = 1001;
  if (n == 1) {
    for (int k = 0; k < 10; k++) {
      for (int i = 0; i < (m); i++) {
        for (int j = 0; j < (2); j++) {
          if (data[i][1] == k) ans = min(ans, k);
        }
      }
    }
  }
  if (n == 2) {
    for (int k = 10; k < 100; k++) {
      bool b = 1;
      for (int i = 0; i < (m); i++) {
        for (int j = 0; j < (2); j++) {
          if (data[i][0] == 1) {
            int l = k / 10;
            if (l != data[i][1]) b = 0;
          }
          if (data[i][0] == 2) {
            int l = k % 10;
            if (l != data[i][1]) b = 0;
          }
        }
      }
      if (b == 1) ans = min(ans, k);
    }
  }
  if (n == 3) {
    for (int k = 100; k < 1000; k++) {
      bool b = 1;
      for (int i = 0; i < (m); i++) {
        for (int j = 0; j < (2); j++) {
          if (data[i][0] == 1) {
            int l = k / 100;
            if (l != data[i][1]) b = 0;
          }
          if (data[i][0] == 2) {
            int l = (k % 100) / 10;
            if (l != data[i][1]) b = 0;
          }
          if (data[i][0] == 3) {
            int l = k % 10;
            if (l != data[i][1]) b = 0;
          }
        }
      }
      if (b == 1) ans = min(ans, k);
    }
  }
  if (ans == 1001) ans = -1;
  cout << ans << endl;
}
