#include <bits/stdc++.h>
using namespace std;
vector<int> a[5];
int main() {
  int n, m;
  cin >> n >> m;
  int s, c;
  for (int i = 1; i <= m; i++) {
    cin >> s >> c;
    if (c > 0) a[s].push_back(c);
  }
  for (int i = 1; i <= n; i++) {
    if (a[i].size() == 0) {
      if (i == 1) {
        if (n == 1) {
          cout << 0 << endl;
          return 0;
        } else {
          cout << -1 << endl;
          return 0;
        }
      }
      if (i == 2) cout << 0;
      if (i == 3) cout << 0;
    } else {
      sort(a[i].begin(), a[i].end());
      cout << a[i][0];
    }
  }
  return 0;
}
