#include <bits/stdc++.h>
using namespace std;
template <class t, class u>
void chmax(t& a, u b) {
  if (a < b) a = b;
}
template <class t, class u>
void chmin(t& a, u b) {
  if (b < a) a = b;
}
int data[10][10][10];
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; ++i) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      for (int r = 0; r < 10; ++r) {
        data[i][j][r] = 0;
      }
    }
  }
  for (int i = 0; i < M; ++i) {
    if (s[i] == 1) {
      for (int j = 0; j < 10; ++j) {
        for (int r = 0; r < 10; ++r) {
          data[c[i]][j][r]++;
        }
      }
    }
    if (s[i] == 2) {
      for (int j = 0; j < 10; ++j) {
        for (int r = 0; r < 10; ++r) {
          data[j][c[i]][r]++;
        }
      }
    }
    if (s[i] == 3) {
      for (int j = 0; j < 10; ++j) {
        for (int r = 0; r < 10; ++r) {
          data[j][r][c[i]]++;
        }
      }
    }
  }
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      for (int r = 0; r < 10; ++r) {
        if (data[i][j][r] == M) {
          if (N == 1) {
            if (i == 0 && j == 0) {
              cout << r << endl;
              return 0;
            }
          }
          if (N == 2) {
            if (i == 0 && j != 0) {
              cout << j << r << endl;
              return 0;
            }
          }
          if (N == 3) {
            if (i != 0) {
              cout << i << j << r << endl;
              return 0;
            }
          }
        }
      }
    }
  }
  cout << -1 << endl;
}
