#include <bits/stdc++.h>
using namespace std;
using ll = long long;
pair<int, int> f(int x, int y) { return pair<int, int>(x, y); }
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> d(4, vector<int>(11, 0));
  vector<pair<int, int>> ps;
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    pair<int, int> q = f(s, c);
    ps.push_back(q);
  }
  bool val = true;
  for (int i = 0; i < (m); ++i) {
    ++d[ps[i].first][ps[i].second];
  }
  for (int i = 1; i < (n + 1); ++i) {
    int tmpsum = 0;
    for (int j = 0; j < (10); ++j) {
      if (d[i][j] > 0) ++tmpsum;
    }
    if (tmpsum > 1) val = false;
  }
  for (int i = 0; i < (ps.size()); ++i) {
    if (ps[i].first > n) val = false;
    if (ps[i].first == 1 && ps[i].second == 0) val = false;
    if ((ps[i].first == 1 && ps[i].second == 0) &&
        (ps[i].first == 2 && ps[i].second == 0))
      val = false;
  }
  sort(ps.begin(), ps.end());
  if (val) {
    vector<int> ans(n, 0);
    for (int i = 0; i < (n); ++i) {
      for (int j = 0; j < (m); ++j) {
        if (ps[j].first == i + 1) {
          ans[i] = ps[j].second;
          break;
        }
      }
    }
    for (int i = 0; i < (n); ++i) cout << ans[i];
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
