#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  string num(n, '0');
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    --s;
    if (num[s] == '0' || num[s] == ('0' + c))
      num[s] = '0' + c;
    else {
      cout << "-1"
           << "\n";
      return 0;
    }
  }
  cout << (num[0] != '0' ? stoi(num) : -1) << "\n";
}
