#include <bits/stdc++.h>
using namespace std;
int s[6], c[6];
int n, m;
inline bool judge(int x) {
  int digits[n + 1];
  int index = n + 1;
  do {
    digits[index--] = x % 10;
    x /= 10;
  } while (x);
  if (index) return false;
  for (register int i = 1; i <= m; ++i)
    if (digits[s[i]] != c[i]) return false;
  return true;
}
signed main() {
  register int i;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; ++i) scanf("%d%d", &s[i], &c[i]);
  for (i = 1; i <= 1000; ++i)
    if (judge(i)) {
      printf("%d\n", i);
      return 0;
    }
}
