#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, k, p, d;
  int dig[4];
  memset(dig, -1, sizeof(dig));
  cin >> n >> m;
  set<int> cnt;
  for (i = 0; i < m; i++) {
    cin >> p >> d;
    if (dig[p] == -1)
      dig[p] = max(dig[p], d);
    else
      dig[p] = min(dig[p], d);
    cnt.insert(p);
  }
  int flag = 0;
  if (find(cnt.begin(), cnt.end(), n) == cnt.end()) {
    cout << "-1" << endl;
  } else {
    if ((dig[1] == 0 && n != 1) || dig[1] == -1)
      flag = 1;
    else {
      cout << dig[1];
      for (i = 2; i <= n; i++) {
        if (dig[i] == -1) {
          dig[i] = 0;
          cout << "0";
        } else
          cout << dig[i];
      }
    }
    if (flag == 1) cout << "-1" << endl;
  }
}
