#include <bits/stdc++.h>
using namespace std;
int a[10];
bool flag[3][3], check = true;
int main() {
  int n, m;
  cin >> n >> m;
  int c, b;
  for (int i = 1; i <= m; i++) {
    cin >> c >> b;
    if (a[c] > 0 && a[c] != b)
      check = false;
    else {
      a[c] = b;
    }
  }
  if (a[1] == 0 && n > 1) check = false;
  if (!check)
    cout << -1;
  else {
    for (int i = 1; i <= n; i++) cout << a[i];
  }
}
