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