#include <bits/stdc++.h>
using namespace std;
int n, m;
bool compIntp(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first) {
    return a.second > b.second;
  } else {
    return a.first > b.first;
  }
}
priority_queue<pair<int, int>, vector<pair<int, int>>,
               function<bool(pair<int, int>, pair<int, int>)>>
    que([](pair<int, int> a, pair<int, int> b) {
      if (a.first == b.first) {
        return a.second > b.second;
      } else {
        return a.first > b.first;
      }
    });
int nums[3];
int solve() {
  int res = 0;
  int lasti = -1, lastn = -1;
  while (!que.empty()) {
    pair<int, int> a = que.top();
    if (n != 1 && a.first == 1 && a.second == 0) return -1;
    if (a.first == lasti && a.second != lastn) return -1;
    if (a.first == lasti && a.second == lastn) {
      que.pop();
      continue;
    }
    res += a.second * ((int)pow(10, n - (a.first)));
    que.pop();
    lasti = a.first;
    lastn = a.second;
  };
  return res;
}
int main() {
  cin >> n;
  cin >> m;
  for (int i = 0; i < m; i++) {
    pair<int, int> p;
    cin >> p.first;
    cin >> p.second;
    que.push(p);
  }
  printf("%d\n", solve());
}
