#include <bits/stdc++.h>
using namespace std;
bool check(int num, vector<vector<int>> a) {
  vector<int> b;
  while (num != 0) {
    b.push_back(num % 10);
    num /= 10;
  }
  int n = b.size();
  reverse(b.begin(), b.end());
  bool ok = true;
  for (int i = 0; i < n; i++) {
    for (auto x : a[i]) {
      if (b[i] != x) ok = false;
    }
  }
  return ok;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(n);
  for (int i = 0; i < m; i++) {
    int pos, val;
    cin >> pos >> val;
    pos--;
    a[pos].push_back(val);
  }
  if (n == 1) {
    for (int i = 0; i < 10; i++) {
      if (check(i, a)) {
        cout << i;
        return 0;
      }
    }
  } else if (n == 2) {
    for (int i = 10; i < 100; i++) {
      if (check(i, a)) {
        cout << i;
        return 0;
      }
    }
  } else {
    for (int i = 100; i < 1000; i++) {
      if (check(i, a)) {
        cout << i;
        return 0;
      }
    }
  }
  cout << -1;
}
