#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M, 0);
  vector<int> c(M, 0);
  for (int ii = 0; ii < M; ++ii) {
    cin >> s[ii] >> c[ii];
  }
  if (N == 1) {
    int ans = -1;
    for (int ii = 0; ii < 9; ++ii) {
      bool OK = true;
      for (int jj = 0; jj < M; ++jj) {
        if (c[jj] != ii) {
          OK = false;
          break;
        }
      }
      if (OK) {
        ans = ii;
        break;
      }
    }
    cout << ans << endl;
    return 0;
  }
  if (N == 2) {
    int ans = -1;
    for (int ii = 10; ii < 99; ++ii) {
      bool OK = true;
      int bottom = ii % 10;
      int top = (ii - bottom) / 10;
      for (int jj = 0; jj < M; ++jj) {
        if (s[jj] == 1) {
          if (c[jj] != top) {
            OK = false;
            break;
          }
        }
        if (s[jj] == 2) {
          if (c[jj] != bottom) {
            OK = false;
            break;
          }
        }
      }
      if (OK) {
        ans = ii;
        break;
      }
    }
    cout << ans << endl;
    return 0;
  }
  if (N == 3) {
    int ans = -1;
    for (int ii = 100; ii < 999; ++ii) {
      bool OK = true;
      int tmp = ii % 100;
      int top = (ii - tmp) / 100;
      int bottom = tmp % 10;
      int middle = (ii - bottom) / 10;
      for (int jj = 0; jj < M; ++jj) {
        if (s[jj] == 1) {
          if (c[jj] != top) {
            OK = false;
            break;
          }
        }
        if (s[jj] == 2) {
          if (c[jj] != middle) {
            OK = false;
            break;
          }
        }
        if (s[jj] == 3) {
          if (c[jj] != bottom) {
            OK = false;
            break;
          }
        }
      }
      if (OK) {
        ans = ii;
        break;
      }
    }
    cout << ans << endl;
    return 0;
  }
  return 0;
}
