#include <bits/stdc++.h>
long long GCD(long long x, long long y) { return y ? GCD(y, x % y) : x; }
long long LCM(long long x, long long y) { return x * y / GCD(x, y); }
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int ans = -1;
  vector<int> sv(m);
  vector<int> sc(m);
  for (int i = 0; i < m; i++) {
    cin >> sv[i];
    cin >> sc[i];
  }
  bool aru = false;
  for (int i = 0; i < m; i++) {
    if (sv[i] == 1 && sc[i] != 0) aru = true;
  }
  if (!aru) {
    cout << -1 << endl;
    return 0;
  }
  vector<string> vecS(3);
  for (int i = 0; i < m; i++) {
    int cou = sv[i] - 1;
    if (vecS[cou] == "") {
      vecS[cou] = to_string(sc[i]);
    } else {
      if (vecS[cou] > to_string(sc[i])) {
        vecS[cou] = to_string(sc[i]);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (vecS[i] == "") {
      vecS[i] = "0";
    }
  }
  for (int i = 0; i < n; i++) {
    cout << vecS[i];
  }
}
