#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, i = 0;
  int s[3];
  int c[9];
  int a[3] = {0, 0, 0}, b[3];
  cin >> N >> M;
  for (auto i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (i = 0; i < M; i++) {
    if (s[i] == 1 && c[i] == 0) {
      cout << "-1";
      return 0;
    }
    b[s[i] - 1] = c[i];
    if (a[s[i] - 1] != b[s[i] - 1] && a[s[i] - 1] != 0) {
      cout << "-1";
      return 0;
    }
    a[s[i] - 1] = c[i];
  }
  for (i = 0; i < N; i++) {
    cout << a[i];
  }
}
