#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(NULL);
  int n, m, s, c, i;
  string str = "";
  map<int, int> mp;
  map<int, int>::iterator it;
  cin >> n >> m;
  int f = 0;
  for (i = 0; i < m; i++) {
    cin >> s >> c;
    if (mp[s] > 0 && mp[s] != c)
      f = 1;
    else
      mp[s] = c;
  }
  if (f == 1)
    cout << -1;
  else {
    int x, f = 0;
    it = mp.begin();
    while (it != mp.end()) {
      if (it == mp.begin()) {
        if (it->first == 1)
          str += (char)it->second + 48;
        else {
          f = 1;
          break;
        }
      } else {
        if (it->first - 1 == x)
          str += (char)it->second + 48;
        else {
          for (int j = x; j < it->first - 1; j++) str += "0";
          str += (char)it->second + 48;
        }
      }
      x = it->first;
      it++;
    }
    if (f == 0) {
      while (str.length() < n) str += "0";
      cout << str;
    } else
      cout << -1;
  }
  return 0;
}
