#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s, v, flag = 0;
  map<int, int> vis;
  cin >> n >> m;
  while (m--) {
    cin >> s >> v;
    if (!vis[s]) {
      vis[s] = v;
    } else if (vis[s] != v) {
      flag = 1;
    }
  }
  if (n == 3 && vis[1] == 0)
    flag = 1;
  else if (n == 2 && (vis[2] == 0 || vis[1]))
    flag = 1;
  else if (n == 1 && (vis[3] == 0 || vis[1] || vis[2]))
    flag = 1;
  if (n == 1 && m == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (vis[1] == 0 && n != 1) {
    cout << -1 << endl;
    return 0;
  }
  if (flag)
    cout << "-1" << endl;
  else {
    for (int i = 1; i <= n; i++) {
      if (vis[i])
        cout << vis[i];
      else if (i == 1)
        cout << 1;
      else
        cout << 0;
    }
    cout << endl;
  }
  return 0;
}
