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