#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N], b[N];
pair<int, int> p[N];
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> p[i].first >> p[i].second;
  sort(p, p + m);
  if (p[0].second == 0 || p[0].first != 1) {
    cout << "-1";
    return 0;
  }
  for (int i = 0; i < m - 1; i++)
    if (p[i].first > n ||
        (p[i].first == p[i + 1].first && p[i].second != p[i + 1].second)) {
      cout << "-1";
      return 0;
    }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    if (p[i].first == p[i + 1].first) continue;
    b[p[i].first] = p[i].second;
  }
  for (int i = 1; i <= 1000; i++) {
    if (i / 100 == b[1] && i / 10 % 10 == b[2] && i % 10 == b[3]) {
      cout << i;
      return 0;
    }
  }
  cout << ans;
  return 0;
}
