#include <bits/stdc++.h>
using namespace std;
using LLint = long long int;
const int mod = 1000000007;
int main() {
  int N, M;
  int S[6];
  string C[6];
  cin >> N >> M;
  for (int i = 0; i < M; ++i) cin >> S[i] >> C[i];
  for (int i = 0; i < 1000; ++i) {
    bool check = true;
    string num = to_string(i);
    int ii = i;
    int digit = 1;
    while (1) {
      ii /= 10;
      if (ii > 0)
        ++digit;
      else
        break;
    }
    if (digit == N) {
      for (int j = 0; j < M; ++j) {
        if (num[S[j] - 1] == C[j][0]) {
        } else
          check = false;
      }
    } else
      check = false;
    if (check) {
      cout << i;
      break;
    }
  }
  return 0;
}
