#include <bits/stdc++.h>
using namespace std;
int a[5] = {0};
int main() {
  ios::sync_with_stdio(false);
  string s;
  int n, m;
  cin >> n >> m;
  int f = 1;
  for (int i = 0; i <= n; i++) {
    a[i] = -1;
  }
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (s == -1 && c == 0) f = 0;
    if (a[s] != -1) {
      if (a[s] != c) f = 0;
    }
    if (!f) continue;
    a[s] = c;
  }
  if (!f)
    cout << "-1" << endl;
  else {
    if (a[1] == -1) a[1] = 1;
    for (int i = 1; i <= n; i++) {
      if (a[i] != -1)
        cout << a[i];
      else
        cout << 0;
    }
  }
  return 0;
}
