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