#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int n, m, s, c;
  int s1, s2, s3;
  s1 = s2 = s3 = -1;
  cin >> n >> m;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s >> c;
    if (s == 1 && (s1 == -1 || s1 == c)) {
      s1 = c;
    } else if (s == 2 && (s2 == -1 || s2 == c)) {
      s2 = c;
    } else if (s == 3 && (s3 == -1 || s3 == c)) {
      s3 = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  int ans = 0;
  if (m == 0) {
    if (n == 3)
      ans = 100;
    else if (n == 2)
      ans = 10;
    else
      ans = 0;
  } else if (n == 3) {
    if (s1 == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (s1 == -1) s1 = 0;
    if (s2 == -1) s2 = 0;
    if (s3 == -1) s3 = 0;
    for (int i = 100; i < 1000; i++) {
      int a1, a2, a3;
      string str = to_string(i);
      a1 = str[0] - '0';
      a2 = str[1] - '0';
      a3 = str[2] - '0';
      if (a3 == s3 && a2 == s2 && a1 == s1) {
        ans = i;
        break;
      }
    }
  } else if (n == 2) {
    if (s1 == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (s1 == -1) s1 = 0;
    if (s2 == -1) s2 = 0;
    for (int i = 10; i < 100; i++) {
      int a1, a2;
      string str = to_string(i);
      a1 = str[0] - '0';
      a2 = str[1] - '0';
      if (a2 == s2 && a1 == s1) {
        ans = i;
        break;
      }
    }
  } else if (n == 1) {
    ans = s1;
  }
  cout << ans << endl;
  return 0;
}
