#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > SC;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    SC.push_back(make_pair(s, c));
  }
  int ans = 0;
  for (int num = 0; num < 1000; num++) {
    int k[3] = {0};
    int nu = num;
    for (int i = 0; i < 3; i++) {
      k[2 - i] = (nu % 10);
      nu /= 10;
    }
    int flag = 0;
    for (int i = 0; i < m; i++) {
      if (k[SC[i].first - 1] != SC[i].second) {
        flag = 1;
      }
    }
    if (flag == 0) {
      ans = num;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
