#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  int a[m + 1];
  for (int i = 1; i <= m; i++) {
    a[i] = 0;
  }
  pair<int, int> p[50];
  for (int i = 0; i < m; i++) {
    cin >> p[i].first >> p[i].second;
  }
  sort(p, p + m);
  for (int i = 0; i < m - 1; i++) {
    if (p[i].first == p[i + 1].first && p[i].second != p[i + 1].second) {
      cout << "-1";
      return 0;
    }
  }
  if (p[0].first == 1 && p[0].second == 0) {
    if (n > 1) {
      cout << "-1";
      return 0;
    } else {
      cout << "0";
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    a[p[i].first] = p[i].second;
  }
  if (a[1] == 0 && n > 1) a[1] = 1;
  for (int i = 1; i <= m; i++) {
    cout << a[i];
  }
  return 0;
}
