#include <bits/stdc++.h>
using namespace std;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;
const int INF = 2 * 1e9;
int main() {
  long long n, m, s, c, a[5] = {0};
  bool x = 0, y = 0;
  set<long long> st[5];
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    cin >> s >> c;
    if (st[s].size() > 0 && a[s] != c) x = 1;
    a[s] = c;
    st[s].insert(c);
  }
  for (long long i = 1; i <= n; i++) {
    if (!y && i != n) {
      if (a[i] != 0)
        y = 1;
      else {
        if (st[i].size() > 0) {
          x = 1;
          break;
        } else {
          a[i] = 1;
        }
      }
    }
  }
  if (x)
    cout << -1;
  else
    for (long long i = 1; i <= n; i++) cout << a[i];
}
