#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, -1);
  int flg = 1;
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    --s;
    if (ans[s] == -1)
      ans[s] = c;
    else if (ans[s] != c)
      flg = 0;
  }
  if (ans[0] == -1)
    ans[0] = 1;
  else if (ans[0] == 0)
    flg = 0;
  for (int i = 1; i < n; ++i) {
    if (ans[i] == -1) ans[i] = 0;
  }
  if (flg) {
    for (int i = 0; i < n; ++i) cout << ans[i];
    cout << endl;
  } else
    cout << -1 << endl;
  return 0;
}
