#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> A(M, vector<int>(2));
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> A.at(i).at(j);
    }
  }
  if (N == 3) {
    int flag2 = 0;
    for (int i = 100; i < 1000; i++) {
      int flag = 0;
      for (int j = 0; j < M; j++) {
        if (A.at(j).at(0) == 1) {
          if (A.at(j).at(1) != i / 100 % 10) {
            flag = 1;
          }
        }
        if (A.at(j).at(0) == 2) {
          if (A.at(j).at(1) != i / 10 % 10) {
            flag = 1;
          }
        }
        if (A.at(j).at(0) == 3) {
          if (A.at(j).at(1) != i % 10) {
            flag = 1;
          }
        }
      }
      if (flag == 0) {
        flag2 = 1;
        cout << i << endl;
        break;
      }
    }
    if (flag2 == 0) {
      cout << -1 << endl;
    }
  } else if (N == 2) {
    int flag2 = 0;
    for (int i = 10; i < 100; i++) {
      int flag = 0;
      for (int j = 0; j < M; j++) {
        if (A.at(j).at(0) == 1) {
          if (A.at(j).at(1) != i / 100 % 10) {
            flag = 1;
          }
        }
        if (A.at(j).at(0) == 2) {
          if (A.at(j).at(1) != i / 10 % 10) {
            flag = 1;
          }
        }
        if (A.at(j).at(0) == 3) {
          if (A.at(j).at(1) != i % 10) {
            flag = 1;
          }
        }
      }
      if (flag == 0) {
        flag2 = 1;
        cout << i << endl;
        break;
      }
    }
    if (flag2 == 0) {
      cout << -1 << endl;
    }
  } else if (N == 1) {
    int flag2 = 0;
    for (int i = 1; i < 10; i++) {
      int flag = 0;
      for (int j = 0; j < M; j++) {
        if (A.at(j).at(0) == 1) {
          if (A.at(j).at(1) != i / 100 % 10) {
            flag = 1;
          }
        }
        if (A.at(j).at(0) == 2) {
          if (A.at(j).at(1) != i / 10 % 10) {
            flag = 1;
          }
        }
        if (A.at(j).at(0) == 3) {
          if (A.at(j).at(1) != i % 10) {
            flag = 1;
          }
        }
      }
      if (flag == 0) {
        flag2 = 1;
        cout << i << endl;
        break;
      }
    }
    if (flag2 == 0) {
      cout << -1 << endl;
    }
  }
}
