#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> mp, mp2;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    mp[i + 1] = 0;
  }
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    mp2[s] += 1;
    if (mp2[s] <= 1) {
      mp[s] = c;
    } else {
      if (mp[s] == c) {
        break;
      } else {
        mp[1] = 0;
        break;
      }
    }
  }
  string s;
  if (mp[1] == 0) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < n; i++) {
      s += to_string(mp[i + 1]);
    }
    cout << s << endl;
  }
}
