#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  set<long long> s[10];
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    s[x].insert(y);
  }
  long long cnt = 0;
  bool b = 1;
  for (long long i = 0; i < 10; i++) {
    cnt += s[i].size();
    if (s[i].size() > 1) b = 0;
  }
  if (n > 1) {
    if (*s[1].begin() == 0) b = 0;
  }
  long long x = 0;
  if (!b) {
    cout << -1 << '\n';
  } else {
    for (long long i = 1; i < 4; i++) {
      x *= 10;
      x += *s[i].begin();
    }
    if (n > 1 && x == 0)
      cout << -1 << '\n';
    else
      cout << x << '\n';
  }
}
