#include <bits/stdc++.h>
using namespace std;
int s[4], c[10], ans[4] = {0, 0, 0, 0}, v[4] = {0};
int n, m;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> s[i] >> c[i];
    if (ans[s[i]] == 0 && v[s[i]] == 0) ans[s[i]] = c[i], v[s[i]] = 1;
    if (v[s[i]] == 1 && ans[s[i]] != c[i]) {
      cout << "-1" << endl;
      return 0;
    }
  }
  int cnt = 0, flag = 0;
  for (int i = 1; i <= n; i++) {
    if (flag == 0 && ans[i] != 0) {
      flag = 1;
      cnt++;
    } else if (flag == 1) {
      cnt++;
    }
  }
  if (flag == 0 && n == 1) cout << "0";
  if (cnt == n) {
    for (int i = 1; i <= n; i++) {
      cout << ans[i];
    }
  } else {
    cout << "-1";
  }
}
