#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string res = string(n, ' ');
  for (int i = 0; i < m; i++) {
    int pos, num;
    cin >> pos >> num;
    pos--;
    if (res[pos] != ' ' && res[pos] != num + '0') {
      cout << -1;
      return 0;
    }
    res[pos] = (num) + '0';
  }
  if (res[0] == '0' && n > 1) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (res[i] == ' ') {
      for (int j = 0; j <= 9; j++) {
        res[i] = j + '0';
        break;
      }
    }
  }
  for (auto ch : res) cout << ch;
}
