#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = (0); i < (M); ++i) {
    cin >> s[i] >> c[i];
  }
  int mn = pow(10, N - 1);
  int mx = pow(10, N) - 1;
  int ans = 2e9;
  for (int i = (0); i < (10); ++i) {
    for (int j = (0); j < (10); ++j) {
      for (int k = (0); k < (10); ++k) {
        bool ok = true;
        int x = i * 100 + j * 10 + k;
        if (x < mn || x > mx) {
          ok = false;
          break;
        }
        for (int m = (0); m < (M); ++m) {
          if (s[m] == 1 && c[m] != i) {
            ok = false;
            break;
          }
          if (s[m] == 2 && c[m] != j) {
            ok = false;
            break;
          }
          if (s[m] == 3 && c[m] != k) {
            ok = false;
            break;
          }
        }
        if (ok) {
          ans = min(ans, x);
        }
      }
    }
  }
  cout << (ans == 2e9 ? -1 : ans) << endl;
}
