#include <bits/stdc++.h>
using namespace std;
struct ac {
  int s, c;
};
map<int, int> mp;
ac a[100];
int ans[4];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a[i].s >> a[i].c;
  }
  int flag = 0;
  for (int i = 1; i <= m; i++) {
    if (mp[a[i].s] == 0) {
      ans[a[i].s] = a[i].c;
      mp[a[i].s]++;
    } else {
      if (ans[a[i].s] != a[i].c) {
        flag = 1;
        break;
      }
    }
  }
  if (flag)
    cout << -1 << '\n';
  else {
    if (ans[1] == 0 && n != 1) {
      cout << -1 << '\n';
    } else
      cout << ans[1] << ans[2] << ans[3] << '\n';
  }
}
