#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int s, c;
  bool flag = false;
  string ans = "";
  map<int, int> digit;
  cin >> n >> m;
  for (int i = 1; i < 4; i++) digit[i] = -1;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (digit[s] != -1 and c != digit[s]) {
      flag = true;
    } else {
      digit[s] = c;
    }
  }
  if (digit[1] == 0) flag = true;
  for (int i = 1; i <= n; i++) {
    if (digit[i] == -1) {
      if (i == 1)
        ans += '1';
      else
        ans += '0';
    } else
      ans += to_string(digit[i]);
  }
  if (flag)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
