#include <bits/stdc++.h>
using namespace std;
int a[4];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, flag = 0;
  memset(a, -1, sizeof(a));
  cin >> n >> m;
  for (int s, c, i = 0; i < m; i++) {
    cin >> s >> c;
    if (a[s] != -1 && a[s] != c)
      flag = 1;
    else if (a[s] == -1)
      a[s] = c;
  }
  if (a[1] == 0 && n > 1) flag = 1;
  if (!flag) {
    for (int i = 1; i <= n; i++) {
      if (a[i] == -1)
        cout << 0;
      else
        cout << a[i];
    }
  } else
    cout << -1;
  return 0;
}
