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