#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  map<int, int> check;
  int flag;
  for (int i = 0; i < (m); ++i) {
    int s;
    int c;
    cin >> s;
    cin >> c;
    if (s == 1 && c == 0) flag = 0;
    mp[s] = c;
    check[s]++;
    if (check[s] == 1) check[s + 3] = c;
    if (check[s] > 1 && c != check[s + 3]) flag = 0;
  }
  if (flag != 0) {
    for (auto p : mp) {
      int i = 1;
      if (i == p.first)
        cout << p.second;
      else if (i == 1)
        cout << 1;
      else
        cout << 0;
      i++;
    }
  } else {
    cout << "-1";
  }
  return 0;
}
