#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1E6;
inline void fastio() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
signed main() {
  fastio();
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n, -1);
  for (long long i = (0); i < (m); i++) {
    long long x, y;
    cin >> x >> y;
    if (a[--x] != -1 && a[x] != y) {
      cout << -1;
      return 0;
    }
    a[x] = y;
  }
  if (n != 1 && a[0] == 0)
    cout << -1;
  else {
    if (a[0] == -1)
      cout << 1;
    else
      cout << a[0];
    if (n >= 2) cout << (a[1] == -1 ? 0 : a[1]);
    if (n >= 3) cout << (a[2] == -1 ? 0 : a[2]);
  }
}
