#include <bits/stdc++.h>
using namespace std;
const int N = 4;
int h[N];
int s, c;
int n, m;
int main() {
  memset(h, -1, sizeof h);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (h[s] != -1 && h[s] != c) {
      puts("-1");
      return 0;
    }
    h[s] = c;
  }
  if (h[1] == 0 || h[1] == -1) {
    puts("-1");
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (h[i] == -1) {
      cout << "0";
    } else {
      cout << h[i];
    }
  }
  cout << endl;
  return 0;
}
