#include <bits/stdc++.h>
using namespace std;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v;
  unordered_map<int, int> mx;
  bool flag = 0;
  while (m--) {
    int s, c;
    cin >> s >> c;
    if (mx.find(s) == mx.end()) {
      v.push_back({s, c});
      mx[s] = c;
    } else {
      if (mx[s] != c) {
        flag = 1;
      }
    }
  }
  if (flag == 1) {
    cout << "-1" << endl;
    return 0;
  }
  sort(v.begin(), v.end());
  string s;
  for (int i = 0; i < v.size(); i++) {
    while (s.size() < (v[i].first - 1)) {
      s.push_back('0');
    }
    s.push_back(v[i].second + '0');
  }
  if (stoi(s) > 0) {
    cout << s << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
