#include <bits/stdc++.h>
using namespace std;
long double pi = acos(-1);
const int INF = 1001001001;
int euqlid(int a, int b) {
  int temp;
  temp = a % b;
  if (temp == 0) return b;
  return euqlid(b, temp);
}
long long conbination(long long a, long long b) {
  long long u = 1;
  long long d = 1;
  while (b != 0) {
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s) { return (int(s - '0')); }
char changeS(char alpha) {
  if (0x41 <= alpha and alpha <= 0x5A)
    return (alpha + 0x20);
  else if (0x61 <= alpha and alpha <= 0x7A)
    return (alpha - 0x20);
  return alpha;
}
int fact(int n) {
  if (n == 1) return 1;
  return n * fact(n - 1);
}
int ceil(int a, int b) { return (a + b - 1) / b; }
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  int c[m];
  ;
  for (int i = 0; i < (m); i++) cin >> s[i] >> c[i];
  int ans = -1;
  ;
  for (int i = 0; i < (1000); i++) {
    int cnt = 0;
    string i_str = to_string(i);
    if (i_str.length() == n) {
      ;
      for (int j = 0; j < (m); j++) {
        string temp = to_string(c[j]);
        if (i_str[s[j] - 1] == temp[0]) cnt++;
      }
    }
    if (cnt == m) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}
