#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  set<long long> v[n];
  long long flag = 1;
  for (long long i = 0; i < m; i++) {
    long long s, c;
    cin >> s >> c;
    v[s - 1].insert(c);
    if (s == 1 && c == 0) flag = 0;
  }
  for (long long i = 0; i < n; i++) {
    if (v[i].size() > 1) {
      flag = 0;
    }
  }
  if (flag == 0)
    cout << -1;
  else {
    if (v[0].size() == 1) {
      cout << *(v[0].begin());
    } else {
      if (n == 1)
        cout << 0;
      else
        cout << "1";
    }
    for (long long i = 1; i < n; i++) {
      if (v[i].size() == 1) {
        cout << *(v[i].begin());
      } else {
        cout << "0";
      }
    }
  }
}
