#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int f = 0;
  vector<int> num(n, 0);
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    if (c == 0 && s == 1 && n != 1) {
      f = 1;
      break;
    } else if (num[s - 1] != 0 && num[s - 1] != c) {
      f = 1;
      break;
    } else
      num[s - 1] = c;
  }
  if (f == 1)
    cout << "-1" << endl;
  else {
    for (int i = 0; i < (int)(m); i++) {
      cout << num[i];
    }
  }
}
