#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
ll MOD = 1000000007;
const double PI = acos(-1);
int main() {
  int n, m;
  cin >> n >> m;
  int ans;
  bool ok = true;
  for (int i = 0; i < 1000; i++) {
    string st = to_string(i);
    if (st.size() != n) {
      ok = false;
      continue;
    }
    for (int i = 0; i < m; i++) {
      int s;
      char c;
      cin >> s >> c;
      if (st[s] != c) ok = false;
    }
    if (ok) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}
