#include <bits/stdc++.h>
using namespace std;
int a[10];
int s[10];
int c[10];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < m; i++) {
    a[s[i] - 1] = c[i];
    if (s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (n == 1 && !a[0]) {
    cout << 0 << endl;
    return 0;
  }
  if (!a[0]) a[0] = 1;
  for (int i = 0; i < n; i++) {
    if (!a[i])
      cout << 0;
    else
      cout << a[i];
  }
  cout << endl;
  return 0;
}
