#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> cm;
  int s, c;
  bool bRet = true;
  int ans = -1;
  map<int, int>::iterator it;
  pair<int, int> p;
  for (int i = 0; i < (M); ++i) {
    cin >> s >> c;
    if (cm.insert(pair<int, int>(s, c)).second == false && cm[s] != c) {
      bRet = false;
      break;
    }
  }
  if (M == 0) {
    bRet = false;
  }
  it = cm.find(1);
  if (it == cm.end()) {
    ;
  } else {
    if (it->second == 0) {
      bRet = false;
    }
  }
  if (bRet) {
    ans = 0;
    it = cm.begin();
    for (; it != cm.end(); ++it) {
      int tmp = it->second;
      for (int i = 0; i < (N - it->first); ++i) tmp *= 10;
      ans += tmp;
    }
    int count = 0;
    int ans2 = ans;
    for (int i = 0; i < (N); ++i) {
      if (ans2 != 0) {
        count++;
        ans2 /= 10;
      }
    }
    if (count != N) {
      ans = -1;
    }
  }
  cout << ans << endl;
}
