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