#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return (a % b) ? gcd(b, a % b) : b; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
void solve_A() {
  int n;
  cin >> n;
  if (n % 2 == 0)
    cout << n / 2;
  else
    cout << n / 2 + 1;
}
void solve_B() {
  int a[3][3];
  int n;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> a[i][j];
    }
  }
  cin >> n;
  int b[n];
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    for (int k = 0; k < 3; k++) {
      for (int l = 0; l < 3; l++) {
        if (b[i] == a[k][l]) a[k][l] = -1;
      }
    }
  }
  bool ok = false;
  for (int i = 0; i < 3; i++) {
    if (a[i][0] == -1 && a[i][1] == -1 && a[i][2] == -1) ok = true;
  }
  for (int i = 0; i < 3; i++) {
    if (a[0][i] == -1 && a[1][i] == -1 && a[2][i] == -1) ok = true;
  }
  if (a[0][0] == -1 && a[1][1] == -1 && a[2][2] == -1) ok = true;
  if (a[0][2] == -1 && a[1][1] == -1 && a[2][0] == -1) ok = true;
  if (ok)
    cout << "Yes";
  else
    cout << "No";
}
void solve_C() {
  int n, m;
  cin >> n >> m;
  int ans[n];
  for (int i = 0; i < n; i++) ans[i] = 0;
  bool ok = true;
  int s[m], c[m];
  int packet[15] = {0};
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    packet[c[i]]++;
    for (int j = 0; j < i; j++) {
      if (s[j] == s[i] && c[j] != c[i]) ok = false;
    }
    ans[s[i] - 1] = c[i];
  }
  if (packet[0] == m && n != 1) ok = false;
  if (ok)
    for (int i = 0; i < n; i++) cout << ans[i];
  else
    cout << -1;
}
int main(void) {
  solve_C();
  return 0;
}
