#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s[5], c[5];
  for (int i = 0; i < M; ++i) {
    cin >> s[i] >> c[i];
    s[i] = s[i] - 1;
  }
  int a[3];
  bool flg = true;
  for (int i = 0; i < 3; ++i) a[i] = -1;
  for (int i = 0; i < M; ++i) {
    if (a[s[i]] == -1 || a[s[i]] == c[i])
      a[s[i]] = c[i];
    else
      flg = false;
  }
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    if (a[i] == -1)
      ans = 10 * ans;
    else
      ans = 10 * ans + a[i];
  }
  cout << ((flg) ? ans : -1);
}
