#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ans(3, 0);
  vector<int> flg(3, 0);
  bool chk = true;
  for (int i = 0; i < m; i++) {
    int tmps, tmpc;
    cin >> tmps >> tmpc;
    if (flg[tmps - 1] == 0) {
      ans[tmps - 1] = tmpc;
      flg[tmps - 1] = 1;
    } else {
      if (ans[tmps - 1] == tmpc) {
        continue;
      } else {
        chk = false;
        break;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      if (flg[i] == 0) {
        if (m == 0) {
          ans[i] = 0;
        } else {
          ans[i] = 1;
        }
      } else if (ans[i] == 0) {
        if (n != 1) {
          chk = false;
        }
      }
    } else {
      if (flg[i] == 0) {
        ans[i] = 0;
      }
    }
  }
  int result = 0;
  if (chk) {
    for (int i = 0; i < n; i++) {
      result = result + ans[i] * pow(10, n - i - 1);
      cerr << ans[i] << endl;
    }
  } else {
    result = -1;
  }
  cout << result << endl;
}
