#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  bool check = true;
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < m; i++) {
    if (n != 0 && s[i] == 1 && c[i] == 0) check = false;
    for (int j = 0; j < m; j++) {
      if (i == j) continue;
      if (s[i] == s[j] && c[i] != c[j]) check = false;
    }
  }
  if (m == 0) {
    if (n == 3)
      cout << 100;
    else if (n == 2)
      cout << 10;
    else if (n == 1)
      cout << 0;
  } else if (n == 1 && c[0] == 0)
    cout << 0;
  else if (!check) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < n; i++) {
      int b = 0;
      for (int j = 0; j < m; j++) {
        if (i + 1 == s[j]) b = c[j];
      }
      cout << b;
    }
    cout << endl;
  }
}
