#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  int a = 1, b = 1, c = 0;
  int X = 0;
  cin >> N >> M;
  if (M == 0) {
    cout << 0;
    return 0;
  }
  vector<vector<int>> SC(M, vector<int>(2, 0));
  for (int i = 0; i < M; ++i) {
    cin >> SC[i][0] >> SC[i][1];
  }
  if (M >= 2) {
    for (int i = 0; i < M - 1; ++i) {
      if ((SC[i][0] == SC[i + 1][0] && SC[i][1] != SC[i + 1][1])) {
        cout << -1;
        return 0;
      }
    }
  }
  for (int i = 0; i < M; ++i) {
    if (N >= 2 && SC[i][0] == 1 && SC[i][1] == 0) {
      cout << -1;
      return 0;
    }
  }
  for (int i = 0; i < M; ++i) {
    switch (N) {
      case 1:
        a = 0;
        b = 0;
        c = SC[i][1];
        break;
      case 2:
        a = 0;
        if (SC[i][0] == 1) b = SC[i][1];
        if (SC[i][0] == 2) c = SC[i][1];
        break;
      case 3:
        if (SC[i][0] == 1) a = SC[i][1];
        if (SC[i][0] == 2) b = SC[i][1];
        if (SC[i][0] == 3) c = SC[i][1];
        break;
      default:
        break;
    }
  }
  for (int i = 0; i < M; ++i) {
    switch (N) {
      case 2:
        if (c == 0) b = 1;
        break;
      case 3:
        if (b == 0 && c == 0) a = 1;
        break;
      default:
        break;
    }
  }
  X = 100 * a + 10 * b + c;
  cout << X;
  return 0;
}
