#include <bits/stdc++.h>
using namespace std;
int n, m, ans[9];
pair<int, int> sc[9];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> sc[i].first >> sc[i].second;
    if (sc[i].first == 1 && sc[i].second == 0 && n > 1) {
      cout << -1 << endl;
      return 0;
    }
    for (int j = 0; j < i; j++)
      if (sc[i].first == sc[j].first && sc[i].second != sc[j].second) {
        cout << -1 << endl;
        return 0;
      }
  }
  if (n == 1) {
    if (m == 0)
      cout << 0 << endl;
    else
      cout << sc[0].second << endl;
    return 0;
  }
  memset(ans, -1, sizeof(ans));
  sort(sc, sc + m);
  for (int i = 0; i < sc[0].first; i++) ans[i] = 1;
  for (int i = 0; i < m - 1; i++)
    if (ans[sc[i].first] == -1) {
      ans[sc[i].first] = sc[i].second;
      int t = i;
      for (; i < m && sc[i].first == sc[t].first;) i++;
      for (int j = sc[i - 1].first + 1; j < sc[i].first; j++)
        ans[i] = (n > 0 ? 0 : 1), n--;
    }
  ans[sc[m - 1].first] = sc[m - 1].second;
  for (int i = 1; i <= sc[m - 1].first; i++) cout << ans[i];
  return 0;
}
