#include <bits/stdc++.h>
using namespace std;
bool flag = true;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, m;
  cin >> n >> m;
  int s[m + 1], c[m + 1];
  for (int i = 1; i <= m; i++) {
    cin >> s[i] >> c[i];
  }
  map<int, vector<int> > mp;
  for (int i = 1; i <= m; i++) {
    mp[s[i]].push_back(c[i]);
  }
  set<int> st;
  for (auto &i : mp) {
    st.clear();
    if (mp[i.first].size() > 1) {
      for (int j = 0; j < mp[i.first].size(); j++) {
        st.insert(mp[i.first][j]);
      }
      if (st.size() != 1) {
        flag = false;
        break;
      }
    }
  }
  if (flag == false) {
    cout << "-1" << '\n';
    return 0;
  }
  string str;
  for (int i = 0; i < n; i++) {
    str += '.';
  }
  for (int i = 1; i <= m; i++) {
    int ind = s[i];
    int num = c[i];
    str[ind - 1] = (char)(num + 48);
  }
  for (int i = 0; i < n; i++) {
    if (str[i] == '.') str[i] = (char)48;
  }
  if (str[0] == 48 && n != 1) {
    cout << "-1" << '\n';
    return 0;
  }
  cout << str << '\n';
}
