#include <bits/stdc++.h>
using namespace std;
void solve(void) {
  int N, M;
  cin >> N >> M;
  int count = -1;
  int sflag = 0;
  if (M > 0) {
    int S[M], C[M];
    for (int i = 0; i < (M); i++) {
      cin >> S[i] >> C[i];
    }
    for (int i = 0; i < (pow(10, N)); i++) {
      string A = to_string(i);
      sflag = 0;
      for (int j = 0; j < (M); j++) {
        string D = to_string(C[j]);
        if (D[0] == A[S[j] - 1]) {
          sflag++;
        }
      }
      if (sflag == M) {
        count = i;
        break;
      }
    }
    if (N > 1 && count == 0) {
      count = -1;
    }
  }
  cout << count << endl;
  return;
}
int main(int argc, const char* argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
