#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<char>> v(m, vector<char>(2));
  for (int i = 0; i < m; i++) {
    cin >> v.at(i).at(0) >> v.at(i).at(1);
  }
  string c;
  for (int i = 0; i < n; i++) {
    c += 'o';
  }
  for (int i = 0; i < m; i++) {
    if (c.at(v.at(i).at(0) - '0' - 1) != 'o') {
      if (c.at(v.at(i).at(0) - '0' - 1) != v.at(i).at(1)) {
        cout << "-1" << endl;
        return 0;
      }
    } else
      c.at(v.at(i).at(0) - '0' - 1) = v.at(i).at(1);
  }
  for (int i = 0; i < n; i++) {
    if (c.at(i) == 'o') c.at(i) = '0';
  }
  string ans;
  if (n == 1 and c.at(n - 1) == '0') {
    cout << '0' << endl;
    return 0;
  }
  if (c.at(0) != '0') {
    for (int j = 0; j < n; j++) {
      ans += c.at(j);
    }
  } else {
    cout << "-1" << endl;
    return 0;
  }
  cout << ans << endl;
}
