#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int s[3];
  memset(s, -1, sizeof(s));
  cin >> n >> m;
  int p, c;
  for (int i = (0); i < (m); i++) {
    cin >> p >> c;
    if (p == 1 && c == 0) goto loop;
    if (s[p - 1] == -1)
      s[p - 1] = c;
    else if (s[p - 1] != c)
      goto loop;
  }
  if (s[0] == -1) s[0] = 1;
  for (int i = (1); i < (3); i++)
    if (s[i] == -1) s[i] = 0;
  for (int i = (0); i < (3); i++) cout << s[i];
  return 0;
loop:
  cout << -1;
  return 0;
}
