#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n + 1], b[n + 1];
  vector<vector<int> > v(4);
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
    if (a[i] == 1 && b[i] == 0 && m != 1) {
      cout << "-1\n";
      return 0;
    }
    v[a[i]].push_back(b[i]);
  }
  for (int i = 1; i <= 3; i++) {
    if (v[i].size()) {
      int x = v[i][0], count = 1;
      for (int j = 0; j < v[i].size(); j++) {
        if (v[i][j] != x) {
          cout << "-1\n";
          return 0;
        }
      }
    }
  }
  if (m == 0) {
    cout << "0\n";
    return 0;
  }
  if (v[1].size() == 0)
    cout << 1;
  else
    cout << v[1][0];
  for (int i = 2; i <= n; i++) {
    if (v[i].size() == 0)
      cout << 0;
    else
      cout << v[i][0];
  }
  cout << "\n";
  return 0;
}
