#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
pair<int, int> sr[10];
int n, m;
vector<int> v;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &sr[i].first, &sr[i].second);
    sr[i].first--;
  }
  sort(sr, sr + m);
  bool f = false;
  for (int i = 0; i < m; i++) {
    if (sr[i].first == 0 && sr[i].second == 0) {
      f = true;
      break;
    }
    if (sr[i].first == v.size() - 1 && sr[i].second == v[sr[i].first])
      continue;
    else if (sr[i].first == v.size() - 1 && sr[i].second != v[sr[i].first]) {
      f = true;
      break;
    }
    while (sr[i].first > v.size()) v.push_back(0);
    v.push_back(sr[i].second);
  }
  while (v.size() < n) v.push_back(0);
  if (f)
    printf("-1\n");
  else {
    for (int i = 0; i < v.size(); i++) printf("%d", v[i]);
    printf("\n");
  }
  return 0;
}
