#include <bits/stdc++.h>
using namespace std;
bool compare_by_b(pair<string, int64_t> a, pair<string, int64_t> b) {
  if (a.second != b.second)
    return a.second < b.second;
  else
    return a.first < b.first;
}
bool compare_by_a(pair<int64_t, int64_t> a, pair<int64_t, int64_t> b) {
  if (a.first != b.first)
    return a.first < b.first;
  else
    return a.second < b.second;
}
bool my_compare(pair<string, int64_t> a, pair<string, int64_t> b) {
  if (a.first != b.first) return a.first < b.first;
  if (a.second != b.second)
    return a.second > b.second;
  else
    return true;
}
int main() {
  int64_t n, m;
  cin >> n >> m;
  vector<int64_t> num(n);
  vector<pair<int64_t, int64_t>> a(m);
  for (int64_t i = 0; i < m; i++) {
    cin >> a[i].first >> a[i].second;
    if (a[i].first == n && a[i].second == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (n == 2 && num[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 3 && num[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int64_t i = 0; i < m; i++)
    for (int64_t j = 0; j < i; j++) {
      if (a[i].first == a[j].first) {
        if (a[i].second != a[j].second) {
          cout << -1 << endl;
          return 0;
        }
      }
      sort((a).begin(), (a).end());
      for (int64_t i = 0; i < a.size(); i++)
        if (a[i].first != a[i + 1].first) num[a[i].first - 1] = a[i].second;
    }
  for (int64_t i = 0; i < n; i++) cout << num[i];
  cout << endl;
  return 0;
}
