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