#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
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];
  if (N == 1) {
    for (int i = 1; i <= 9; i++) {
      bool check = true;
      for (int(j) = 0; (j) < (M); (j)++)
        if (c[j] != i) check = false;
      if (check) {
        cout << i << "\n";
        return 0;
      }
    }
  }
  if (N == 2) {
    for (int i = 10; i <= 99; i++) {
      bool check = true;
      int one = i / 10, two = i % 10;
      for (int(j) = 0; (j) < (M); (j)++) {
        if (s[j] == 1)
          if (c[j] != one) check = false;
        if (s[j] == 2)
          if (c[j] != two) check = false;
      }
      if (check) {
        cout << i << "\n";
        return 0;
      }
    }
  }
  if (N == 3) {
    for (int i = 100; i <= 999; i++) {
      bool check = true;
      int now = i;
      int one = i / 100, three = i % 10;
      now -= one * 100;
      int two = now / 10;
      for (int(j) = 0; (j) < (M); (j)++) {
        if (s[j] == 1)
          if (c[j] != one) check = false;
        if (s[j] == 2)
          if (c[j] != two) check = false;
        if (s[j] == 3)
          if (c[j] != three) check = false;
      }
      if (check) {
        cout << i << "\n";
        return 0;
      }
    }
  }
  cout << -1 << "\n";
}
