#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();
const long double EPS = 1e-9;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, string> mp;
  for (int i = 0; i < m; i++) {
    int s;
    string c;
    cin >> s >> c;
    mp[s] = c;
  }
  string res = "";
  bool flag = true;
  int pre_num = -1, k = 0;
  for (auto iter = mp.begin(); iter != mp.end(); iter++) {
    int num = atoi(iter->second.c_str());
    if (k == iter->first) {
      if (pre_num != num) {
        flag = false;
        break;
      }
    } else {
      k++;
      while (k != iter->first) {
        k++;
        res += '0';
      }
      res += iter->second;
    }
    pre_num = num;
  }
  while (res.length() < n) {
    res += '0';
  }
  if (res[0] == '0' && res.length() != 1) flag = false;
  if (flag)
    cout << res << endl;
  else
    cout << "-1" << endl;
}
