#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
int main() {
  int N, M;
  string ans;
  bool exist_ans = true;
  cin >> N >> M;
  for (int i = 0; i < (int)(N); i++) ans += "0";
  int S[M], C[M], fixed[M];
  for (int i = 0; i < (int)(M); i++) cin >> S[i] >> C[i], fixed[i] = 0;
  for (int i = 0; i < (int)(M); i++) {
    if (fixed[S[i] - 1] == 0) {
      ans[S[i] - 1] = C[i] + '0';
      fixed[S[i] - 1] = 1;
    } else if (ans[S[i] - 1] != C[i] + '0') {
      exist_ans = false;
      break;
    }
  }
  if ((ans.size() >= 2) && (ans[0] == '0')) exist_ans = false;
  if (exist_ans)
    cout << ans << endl;
  else
    cout << "-1" << endl;
  return 0;
}
