#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int num[3] = {-1, -1, -1}, s[5], c[5];
  int n, m, temp = 1, Num = 0;
  cin >> n;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> s[i];
    cin >> c[i];
  }
  for (int i = 0; i < m; i++) {
    if (num[s[i] - 1] == -1 || num[s[i] - 1] == c[i])
      num[s[i] - 1] = c[i];
    else {
      temp = 0;
      break;
    }
  }
  if (num[n - 1] < 1) temp = 0;
  if (!temp) {
    cout << -1;
  } else {
    for (int i = 0; i < n; i++) {
      if (num[i] != -1)
        cout << num[i];
      else
        cout << 0;
    }
  }
  return 0;
}
