#include <bits/stdc++.h>
using namespace std;
int N, M;
int s[10], c[10];
string S;
int ans = 10000000;
void dfs(int num) {
  if (num == N) {
    int count = 1;
    for (int i = 0; i < M; i++) {
      if (S[s[i]] != (char)(c[i] + '0')) {
        count = 0;
        break;
      }
    }
    if (S[0] == '0' && N > 1) {
      count = 0;
    }
    int t = 0;
    for (int i = 0; i < N; i++) {
      t += (S[i] - '0') * pow(10, N - i - 1);
    }
    if (ans > t && count == 1) {
      ans = t;
    }
    return;
  }
  for (int i = 0; i < 10; i++) {
    S += to_string(i);
    dfs(num + 1);
  }
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  dfs(0);
  if (ans == 10000000)
    cout << -1;
  else
    cout << ans;
  return 0;
}
