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