#include <bits/stdc++.h>
using namespace std;
int s[10], c[10];
int N, M;
int ans = 100000;
char str[5];
void dfs(int n) {
  if (n == N) {
    int sum = 0;
    for (int i = 0; i < M; i++) {
      if (str[s[i] - 1] == (char)c[i]) {
        sum++;
      }
    }
    if (sum == M && str[0] != '0') {
      int t = 0;
      for (int i = 0; i < N; i++) {
        t += (int)str[i] * pow(10, N - (i + 1));
      }
      if (ans > t) ans = t;
    }
    return;
  }
  for (int i = 0; i <= 9; i++) {
    str[n] = (char)(i);
    dfs(n + 1);
  }
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  if (N == 1) {
    for (int i = 0; i < 10; i++) {
      int num = 0;
      for (int j = 0; j < M; j++) {
        if (i == c[j]) num++;
        if (num == M) {
          if (ans > i) ans = i;
        }
      }
    }
    if (ans == 100000)
      cout << -1;
    else
      cout << ans;
    return 0;
  }
  ans = 100000;
  dfs(0);
  if (ans == 100000) {
    cout << "-1";
  } else
    cout << ans;
  return 0;
}
